у меня подобный код, помоему я его гдето стырил…
class Profile_list(models.Model):
thumbnail = models.ImageField(upload_to='files/avas/thumb/', blank=True, null=True, editable=False)
avatar=models.ImageField(upload_to="files/avas/", verbose_name="Аватар",blank=True)
def save(self, force_insert=False, force_update=False):
#get mtime stats from file
thumb_update = False
if self.thumbnail:
statinfo1 = os.stat(self.avatar.path)
statinfo2 = os.stat(self.thumbnail.path)
if statinfo1 > statinfo2:
thumb_update = True
if self.avatar and not self.thumbnail or thumb_update:
from PIL import Image
THUMB_SIZE = (50, 50)
#self.thumbnail = self.avatar
image = Image.open(self.avatar.path)
if image.mode not in ('L', 'RGB'):
image = image.convert('RGB')
image.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
(head, tail) = os.path.split(self.avatar.path)
(a, b) = os.path.split(self.avatar.name)
if not os.path.isdir(head + '/thumbs'):
os.mkdir(head + '/thumbs')
image.save(head + '\\thumbs\\' + tail)
self.thumbnail = a + '/thumbs/' + b
super(Profile_list, self).save()