我覆盖了下面的保存方法,并使用 get_thumbnails 和 sorl 保存。
但是得到错误'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)
有任何想法吗 ?