3

In my model, users can upload images. For those images I want to store thumbnails too. For the task I'm trying to use django-imagekit but I don't seem to make it work

class Imagen(models.Model):
    def get_image_path(instance, filename):
        ext = filename.split('.')[-1]
        filename = "%s.%s" % (uuid.uuid4(), ext)
        return os.path.join('uploads/images', str(instance.user.id), filename)

    def get_thumb_image_path(instance, path, specname, extension):
        path_thumb = re.sub("(\.\w+$)", "", path)
        path_thumb = "%s%s%s" % (path_thumb, "_thumb", extension)
        return path_thumb

    user = models.ForeignKey(User)
    imagen = models.ImageField(upload_to=get_image_path, format='JPEG')
    imagen_thumb = ImageSpecField([ResizeToFill(92, 116)], image_field='imagen', cache_to=get_thumb_image_path, format='JPEG', options={'quality': 90})
    insert_date = models.DateTimeField(auto_now_add=True, editable=False)

ImageSpecField is suposed to keep the original file and store the new one in cache_to (API) but it does not work,

get_thumb_image_path responds with the same path as get_image_path but with '_thumb' added to the image, like:

uploads/images/1/8836e0d5-8cce-4e3d-b3dc-35ec8ff451ce.jpg
uploads/images/1/8836e0d5-8cce-4e3d-b3dc-35ec8ff451ce_tumb.jpg
avances123
  • 2,224
  • 4
  • 21
  • 21
nachoab
  • 1,908
  • 1
  • 23
  • 36

0 Answers0