I want to save webp image near jpg version.

Now I'm doing it this way:
class ProductImage(models.Model):
    product = models.ForeignKey(
        to=Product,
        related_name='images',
        on_delete=models.CASCADE,
    )

    image = models.ImageField(
        upload_to=upload_product_image,
        default='',
        blank=True,
        max_length=255,
    )

    def save(self, **kwargs):
        super().save(**kwargs)
        self.create_webp_image()

    def create_webp_image(self):
        image = Image.open(self.image.path)
        path = os.path.splitext(self.image.path)[0] + '.webp'
        image.save(path, 'WEBP')

Is there more elegant way to do it?

Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7b4e1100-e147-4b8e-8ef7-db2b29caa747%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to