Created
May 7, 2018 10:27
-
-
Save jerinisready/9d92e3c29e6596a88b045f729a5c8fdc to your computer and use it in GitHub Desktop.
django image store as blob in models.py
This file contains 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 imageStorageAsThumpnail(models.Model) | |
image = models.ImageField(_("Image"), upload_to='chapter_images') | |
_thumbnail = models.TextField( | |
db_column='thumbnail', | |
blank=True) | |
def set_thumbnail(self, data): | |
self._data = base64.b64encode(data) | |
def get_thumbnail(self): | |
return base64.b64decode(self._data) | |
thumbnail = property(get_thumbnail, set_thumbnail) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment