0

Does anyone have experience using ImageKit to manage thumbnails?

I currently have the following in my models.py:

class Item(models.Model):
    id = models.AutoField(primary_key=True)
    owner = models.ForeignKey(
        get_user_model(),
        on_delete=models.SET_NULL,
        null=True,
        blank=True
    )
    image = ProcessedImageField(
        upload_to=image_upload,
        blank=True,
        validators=[validate_image],
        format='JPEG',
        help_text="Max file size is 3 MB."
    )
    image_thumbnail = ImageSpecField(
        source='image',
        processors=[ResizeToFill(50, 50)],
        format='JPEG',
        options={'quality': 60}
    )

I'd like to rename the thumbnail and store it in a particular folder (not the CACHE/images/ folder that ImageKit defaults to), but can't figure out how to do that (and adding an "upload_to" to the thumbnail gives me an error). All help greatly appreciated! Thank you!

1 Answers1

0

According to the docs:

ImageSpecFields, on the other hand, are virtual—they add no fields to your database and don’t require a database. This is handy for a lot of reasons, but it means that the path to the image file needs to be programmatically constructed based on the source image and the spec.

You might just want to stick to the ProcessedImageFIeld if you don't want your files to be stored in a cache folder.

crimsonpython24
  • 2,223
  • 2
  • 11
  • 27
  • Oh interesting, thank you! Are you aware of how to create a thumbnail based on the image uploaded into a separate field? I'm inclined to just run a `post_save` method and manually make one? – mmmmm12345 Jul 29 '20 at 22:14
  • Sorry, I can't answer that question as I only took a quick dip into imagekit before moving out. – crimsonpython24 Jul 30 '20 at 00:41