Skip to content

Instantly share code, notes, and snippets.

@michaelhelmick
Created May 24, 2019 13:52
Show Gist options
  • Save michaelhelmick/054e64cc7f226b73917c93a22b5bcd32 to your computer and use it in GitHub Desktop.
Save michaelhelmick/054e64cc7f226b73917c93a22b5bcd32 to your computer and use it in GitHub Desktop.
class Photo(models.Model):
thumbnail = models.ImageField(...)
def get_thumbnail(self, size='medium'):
"""Get an appropriate size thumbnail.
https://example.com/image.jpg would now be
https://example.com/image_medium.jpg
"""
url_parts = self.thumbnail.url.rsplit('.')
return '{}_{}{}'.format(url_parts[0], size, url_parts[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment