Created
May 16, 2013 12:24
-
-
Save fmariluis/5591351 to your computer and use it in GitHub Desktop.
Custom Django field to save binary data
Django < 1.5
http://djangosnippets.org/snippets/1597/
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
import base64 | |
from django.db import models | |
class Foo(models.Model): | |
_data = models.TextField( | |
db_column='data', | |
blank=True) | |
def set_data(self, data): | |
self._data = base64.encodestring(data) | |
def get_data(self): | |
return base64.decodestring(self._data) | |
data = property(get_data, set_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment