23 lines
687 B
Python
23 lines
687 B
Python
from rest_framework import serializers
|
|
from .models import ProfileModel
|
|
from django.conf import settings
|
|
from django.utils.translation import gettext as _
|
|
|
|
|
|
class ProfileSerializer(serializers.ModelSerializer):
|
|
|
|
username = serializers.ReadOnlyField(source='user.username')
|
|
avatar = serializers.ImageField(required=False)
|
|
|
|
class Meta:
|
|
model = ProfileModel
|
|
fields = ["username", "avatar", "user_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
|