I want to serialize the profile avatar from Wagtail admin with ImageRenditionField. Basing on the answer from the question I tried this:
# models.py
class User(AbstractUser):
def get_avatar(self):
return self.wagtail_userprofile.avatar
# serializers.py
class UserSerializer(serializers.ModelSerializer):
avatar = ImageRenditionField('width-190', source='get_avatar')
class Meta:
model = User
fields = ['id', 'username', 'first_name', 'last_name', 'avatar']
I got this:
Django Version: 3.1.4
Exception Type: AttributeError
Exception Value:
'ImageFieldFile' object has no attribute 'get_rendition'
How do I throw user avatar into ImageRenditionField?