base64 encoding/decoding property for storing binary data in Django TextFields.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
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)

More like this

  1. Base64Field: base64 encoding field for storing binary data in Django TextFields by bikeshedder 4 years, 8 months ago
  2. Transparently encrypt ORM fields using OpenSSL (via M2Crypto) by ncoghlan 2 years, 9 months ago
  3. Custom model field to store dict object in database by rudyryk 4 years ago
  4. CategoriesField by fongandrew 4 years, 8 months ago
  5. Render TextField in Admin by xavierlesa 3 years, 7 months ago

Comments

fero (on February 11, 2012):

thank you very much, good snippet. Testing it now

#

(Forgotten your password?)