[Answered ]-Model save method. Resize image before save

1👍

You’ll need so save your UserImages before you try to access its ImageField.

An example how to do this can be found in this snippet:

Basically:

super(UserImages, self).save()

PS. You model should have a singular name, e.g. UserImage instead of UserImages.

👤miku

1👍

Use django-resized

pip install django-resized

models.py

from django_resized import ResizedImageField

class MyModel(models.Model):
    ...
    image = ResizedImageField(max_width=500, max_height=300, upload_to='whatever')

For more info look at https://github.com/un1t/django-resized

👤un1t

Leave a comment