Advertisement
Guest User

django imagefield

a guest
Nov 8th, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement