Use source keyword argument (instead of overriding get_attribute)

This allows the ImageRenditionField to be used on models that contain an
image field.
pull/3462/head
Karl Hobley 2017-02-10 13:08:40 +00:00 zatwierdzone przez Karl Hobley
rodzic 55eaa0c137
commit 301463a99d
1 zmienionych plików z 1 dodań i 4 usunięć

Wyświetl plik

@ -31,9 +31,6 @@ class ImageRenditionField(Field):
self.filter_spec = filter_spec
super(ImageRenditionField, self).__init__(*args, **kwargs)
def get_attribute(self, instance):
return instance
def to_representation(self, image):
try:
thumbnail = image.get_rendition(self.filter_spec)
@ -50,4 +47,4 @@ class ImageRenditionField(Field):
class AdminImageSerializer(ImageSerializer):
thumbnail = ImageRenditionField('max-165x165', read_only=True)
thumbnail = ImageRenditionField('max-165x165', source='*', read_only=True)