Getting variation URL
delitestudio opened this issue · 2 comments
delitestudio commented
Hello and thanks for this great package!
I was wondering how to get the URL of a variation. I'll explain. I created my model this way:
class UploadedImage(models.Model):
image = stdimage.StdImageField(upload_to=UploadToUUID(),
variations={'thumbnail': {'width': 100, 'height': 100}})
Now I can obtain the full image URL in this way:
image = UploadedImage.objects.get(pk=15)
# the URL is image.image.url
How do I get the thumbnail URL without having to recreate it by hand?
codingjoe commented
Hi @delitestudio that's a good questions, the answer is rather simple, simply call url on the variation. Like so:
obj = UploadedImage.objects.get(pk=15)
obj.image.thumbnail.urlthumbnail being the name of your variation. So if you have a variation called small it would be:
obj.image.small.url
Let me know if we can improve the documentation somehow.
Best
-Joe
delitestudio commented
Great, thank you very much!