Closed elcolie closed 6 years ago
For admin page to work you need to use admin_thumbnail
in list_display
instead of thumbnail
. Currently you are only defining the attribute admin_thumbnail
but does not list it in list_display
for that reason you are not seeing the preview but instead see the relative path to the storage where cached thumbnail is stored.
About the issue with the REST Framework you can look at the code for ModelSerializer
https://github.com/encode/django-rest-framework/blob/3.7.7/rest_framework/serializers.py#L839-L864
there is a mapping between default Django fields and REST Framework fields.
When you are using default models.ImageField
then REST Framework know how to serialize it. The problem is that it does not know anything about 3th party custom fields. You can help it by explicitly say which is the type of the field:
class ExampleSerializer(serializers.ModelSerializer):
thumbnail = serializers.ImageField()
class Meta:
model = Example
fields = [
'image',
'thumbnail',
]
I didn't tested it but you can try.
Thank you very much. I will commit your answer to my repo. It is good example.
Here is my repository https://github.com/elcolie/django-image-discussion
Problems:
thumbnail
. This case I had mention it alreadythumbnail
field inExampleSerializer
it will raises the errorReferences: https://github.com/matthewwithanm/django-imagekit/issues/456