Created
May 24, 2019 13:52
-
-
Save michaelhelmick/054e64cc7f226b73917c93a22b5bcd32 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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