Skip to content

Commit

Permalink
use small in image in api
Browse files Browse the repository at this point in the history
  • Loading branch information
Magdalena Noffke committed Mar 6, 2017
1 parent b80c6df commit c59038d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion euth/users/serializers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
from easy_thumbnails.files import get_thumbnailer
from rest_framework import serializers

from .models import User


class UserSerializer(serializers.ModelSerializer):
avatar = serializers.ImageField()
avatar = serializers.SerializerMethodField()

class Meta:
model = User
fields = ('id', 'username', 'avatar', 'default_avatar')
read_only_fields = ('id', 'username', 'avatar', 'default_avatar')

def get_avatar(self, obj):
if obj.avatar:
image = get_thumbnailer(obj.avatar)['avatar_small']
return image.url


# mails should not be exposed in API, so there is a separate one for this
class UserWithMailSerializer(UserSerializer):
Expand Down

0 comments on commit c59038d

Please sign in to comment.