class CustomUserModelSerializer(serializers.ModelSerializer):
"""give all users"""
status = serializers.SerializerMethodField()
class Meta:
model = CustomUser
fields = ('id', 'email', 'name', 'status', 'avatar')
def get_status(self, obj):
if obj.is_active == True:
status = 'active'
else:
status = 'inactive'
return status
def to_representation(self, instance):
response = super().to_representation(instance)
if not instance.avatar.name:
request = self.context.get('request')
response['avatar'] = request.build_absolute_uri("/media/images/avatar-test.jpg")
return response
вот рабочий сериализатор, спасибо за ответ, который дал нужное направление!