How to get source picture object from thumnail object?

17 views
Skip to first unread message

Samiul Sk

unread,
Jun 26, 2018, 10:37:29 AM6/26/18
to Django ImageKit
I am working on a project which contains a Model with 'product name', 'picture' and 'picture_thumbnail'. Where second one is ImageField and thumbnail one is ImageSpecField. 
So my Model is given below as 'ProductImage'.


class ProductImage(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
owner = models.ForeignKey(User, on_delete=models.CASCADE)
picture = models.ImageField(upload_to=get_uploaded_file_name, blank=True, null=True)
picture_thumbnail = ImageSpecField(source='picture',
processors=[ResizeToFill(200, 150)],
format='JPEG',
options={'quality': 60})


Now I can easily get the thumbnail in Django template like - {{ object.picture_thumbnail.url }}
What do I want to know is - how to get picture object corresponding to picture_thumbnail. Actually I want to show all thumbnail list, related to the Product and by clicking on the thumbnail, I want to get the original picture which is the source of that thumbnail. 
Is there any way to get it? May be directly or indirectly(like by creating similar name, I don't know how)?
Thanks in advance 

kravemir

unread,
Jan 12, 2019, 3:13:07 PM1/12/19
to Django ImageKit

What do I want to know is - how to get picture object corresponding to picture_thumbnail. Actually I want to show all thumbnail list, related to the Product

See https://docs.djangoproject.com/en/2.1/topics/db/examples/many_to_one/ . Especially docs related to querying objects.
 
and by clicking on the thumbnail, I want to get the original picture which is the source of that thumbnail. 
Is there any way to get it? May be directly or indirectly(like by creating similar name, I don't know how)?

For original image, just work with `picture` field. And, for thumbnail image work with `picture_thumbnail` field. For example, construct like like `<a href="PICTURE_URL"><img src="PICTURE_THUMBNAIL_URL"/></a>`.
Reply all
Reply to author
Forward
0 new messages