override save method - 'ImageFile' object has no attribute '_committed'

tuna picture tuna · May 15, 2013 · Viewed 9.4k times · Source

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 ?

Answer

tuna picture tuna · May 15, 2013
self.thumbnail = get_thumbnail(self.original,
                                   '50x50',
                                   crop='center',
                                   quality=99).url

solved my problem ..