Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Sorl Thumbnail with Django Rest Framework #517

Closed
tagmetag opened this issue Oct 4, 2017 · 7 comments
Closed

Use Sorl Thumbnail with Django Rest Framework #517

tagmetag opened this issue Oct 4, 2017 · 7 comments

Comments

@tagmetag
Copy link

tagmetag commented Oct 4, 2017

How can I use sorl thumbnail with DRF? I follow instruction Low API: http://sorl-thumbnail.readthedocs.io/en/latest/examples.html#low-level-api-examples and get error: my_file is not defined in model. Please help me.

@mark-mishyn
Copy link

mark-mishyn commented Nov 2, 2017

This works:

if obj.photo:
    return get_thumbnail(obj.photo, '30x30', crop='center', quality=99).url

and photo is ImageField in your model.

@tagmetag
Copy link
Author

tagmetag commented Nov 6, 2017

Thank you. Hope Sorl Thumbnail support for DRF in the future :)

@SalahAdDin
Copy link

Can you put it in the documentation?

@kidig
Copy link

kidig commented Mar 23, 2018

BTW, I've found a useful package for DRF: https://github.com/dessibelle/sorl-thumbnail-serializer-field

@SalahAdDin
Copy link

@kidig Can you put it at documentation?

@maxim25
Copy link

maxim25 commented Mar 23, 2018

@kidig I've found that this library slows down my app significantly. The HyperlinkedSorlImageField generates an additional query to the db and another to the cache (thourgh get_thumbnail). So if you have a simple m2m relationship with ex. 100 images and the image serializer has 2 HyperlinkedSorlImageField (ex one for the thumbnail and one large), it would create an additional 200 queries.

@Atorich
Copy link

Atorich commented Apr 18, 2018

@maxim25
https://github.com/dessibelle/sorl-thumbnail-serializer-field/blob/master/sorl_thumbnail_serializer/fields.py
There is the whole codebase. Nothing about any extra database queries. Please, check your querysets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants