copy - Dupicate an ImageField in another field of same model while saving the model objects -
i want upload 1 image(location of stores in photo
field of model mentioned below ) , want duplicate photo field thumbnail
programitically.
i tried in way mentioned in class picture(models.model):
below. bytheway resizedimagefield
works , have tested photo
field. needed overwrite def save(self, *args, **kwargs):
method mentioned below.
from django_resized import resizedimagefield class picture(models.model): photo = resizedimagefield('photo', upload_to='photos/%y/%m/%d', size=[636,331]) thumbnail = resizedimagefield('thumbnail', upload_to='thumbnail/%y/%m/%d', size=[150, 100], blank=true, null=true) def save(self, *args, **kwargs): super(picture, self).save(*args, **kwargs) if self.photo: self.thumbnail = resizedimagefield(self.photo) self.thumbnail.save()
i think problem save method calling on self.thumbnail.save()
, try instead:
def save(self, *args, **kwargs): if self.photo: self.thumbnail = resizedimagefield(self.photo) super(picture, self).save(*args, **kwargs)
you may find post useful
Comments
Post a Comment