21 lines
635 B
Python
21 lines
635 B
Python
from rest_framework import serializers
|
|
from .models import ProfileModel
|
|
from django.conf import settings
|
|
|
|
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;
|