notice but without the t
This commit is contained in:
29
profiles/serializers.py
Normal file
29
profiles/serializers.py
Normal file
@ -0,0 +1,29 @@
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
from .models import ProfileModel
|
||||
|
||||
|
||||
class ProfileSerializer(serializers.ModelSerializer):
|
||||
|
||||
username = serializers.ReadOnlyField(source='user.username')
|
||||
avatar = serializers.ImageField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = ProfileModel
|
||||
fields = ["username", "avatar", "id"]
|
||||
|
||||
def validate_avatar(self, value):
|
||||
'''
|
||||
Check that the image is not too large
|
||||
'''
|
||||
if value.size > settings.PROFILE_PICTURE_MAX_SIZE:
|
||||
raise serializers.ValidationError(_('Image is too large.'))
|
||||
return value
|
||||
|
||||
def to_representation(self, instance):
|
||||
data = super().to_representation(instance)
|
||||
data['avatar'] = data['avatar'][data['avatar'].find('/static/'):]
|
||||
return data
|
Reference in New Issue
Block a user