📅  最后修改于: 2022-03-11 14:45:29.525000             🧑  作者: Mango
from django.db import models
from my.images import make_thumbnail
class Image(models.Model):
image = models.ImageField(upload_to='')
thumbnail = models.ImageField(upload_to='', editable=False)
icon = models.ImageField(upload_to='', editable=False)
def save(self, *args, **kwargs):
# save for image
super(Image, self).save(*args, **kwargs)
make_thumbnail(self.thumbnail, self.image, (200, 200), 'thumb')
make_thumbnail(self.icon, self.image, (100, 100), 'icon')
# save for thumbnail and icon
super(Image, self).save(*args, **kwargs)