Question

I am currently using sorl-thumbnail and have a model.

class Entry(models.Model):

    image = ImageWithThumbnailsField(upload_to='uploads/', null=False, blank=True, 
        thumbnail={
            'size':(150,150),
        'options':{'crop':'smart'}
        },
        generate_on_save=True
    )

This model creates 'filename_jpeg_150x150x_crop-smart_q85.jpg' thumbnail in 'uploads' folder and I am trying to access it from my view functions. I'm wondering if there is a simple way to find out the thumbnail's name and path.

Thank you.

Was it helpful?

Solution

Tried using thumbnails_for_file() and all_thumbnails() inside sorl-thumbnail 3.2.5 utils.py, but was unsuccessful. Seemed like those functions were returning thumbnails that were parsed directly from django templates. It just didn't return all thumbnail files.

Ended up just parsing out the file path by

Entry.objects.all()[0].image.thumbnail.relative_url

relative_url shows path and filename 'uploads/test_jpg_150x150_crop-smart_q85.jpg'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top