Skip to content

Instantly share code, notes, and snippets.

@rizumu
Created October 2, 2014 17:26
Show Gist options
  • Save rizumu/ee9b2e7defecb18725e8 to your computer and use it in GitHub Desktop.
Save rizumu/ee9b2e7defecb18725e8 to your computer and use it in GitHub Desktop.
mixin snippet
width = models.PositiveIntegerField(_("height"), db_index=True)
height = models.PositiveIntegerField(_("width"), db_index=True)
def is_horizontal(self):
if float(self.height) / self.width <= 0.7:
return True
def is_vertical(self):
if float(self.height) / self.width > 0.7:
return True
def is_square(self):
if self.width == self.height:
return True
def save(self):
if not self.image:
self.delete()
else:
image = Image.open(cStringIO.StringIO(urllib.urlopen(self.image.url).read()))
self.width, self.height = image.size
super(Poster, self).save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment