SHARE
TWEET

django imagefield

a guest Nov 8th, 2014 210 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Post(models.Model):
  2.     #...
  3.     photo = models.ImageField(upload_to="photo_album")
  4.     thumbnail = models.ImageField(upload_to="photo_album/thumbnails", null=True, blank=True)
  5.  
  6.     def save(self):
  7.         thumb = Image.open(self.photo.file)
  8.         thumb_io = StringIO.StringIO()
  9.         thumb.save(thumb_io,format = thumb.format,)
  10.         self.thumbnail.save(self.photo.name, ContentFile(thumb_io.getvalue()), save=False)
  11.         super(Post, self).save()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top