I override the save method like below, and get_thumbnails and save with sorl..
But get the error 'ImageFile' object has no attribute '_committed'
class HotelPhotos(models.Model):
hotel = models.ForeignKey(Hotel, related_name='photos')
code = models.CharField(max_length=255)
original = models.ImageField(upload_to="media")
medium = models.ImageField(upload_to="media", null=True, editable=False)
thumbnail = models.ImageField(upload_to="media", null=True, editable=False)
def save(self, *args, **kwargs):
super(HotelPhotos, self).save(*args, **kwargs)
self.medium = get_thumbnail(self.original,
'100x100',
crop='center',
quality=99)
self.thumbnail = get_thumbnail(self.original,
'50x50',
crop='center',
quality=99)
super(HotelPhotos, self).save(*args, **kwargs)
Any ideas ?
super
save method twice.super
save will return you an instance use that instance to set additional fields:instance = super(HotelPhotos, self).save(*args, **kwargs)
– Roup