Django rest serializer как использовать разные версии сохраненных изображений?

Hi all, I have a question when working with images.

I have overridden the save method in the models, in order to save multiple versions of the image.

Now I want to use a second saved version of the image in the Serializer, with the proportions changed.

Please tell me how I can do this and is this scenario possible?

models.py

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        img = Image.open(self.image)
        thumbnail_size = (500, 500)
        img.thumbnail(thumbnail_size)
        image_name, image_ext = os.path.splitext(self.image.path)
        custom_path1 = '{}_500{}'.format(image_name, image_ext)
        img.save(custom_path1, "JPEG", optimize=True, quality=75)

Вернуться на верх