36👍
✅
This snippet any good:
http://djangosnippets.org/snippets/1597/
This is possibly the simplest solution for storing binary data in a
TextField.
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)
There’s a couple of other snippets there that might help.
- [Django]-Django-rest-framework 3.0 create or update in nested serializer
- [Django]-Django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured
- [Django]-How to add url parameters to Django template url tag?
10👍
I have been using this simple field for ‘mysql’ backend, you can modify it for other backends
class BlobField(models.Field):
description = "Blob"
def db_type(self, connection):
return 'blob'
- [Django]-Django: How to override form.save()?
- [Django]-Django: "projects" vs "apps"
- [Django]-Django query case-insensitive list match
0👍
Also, check out Django Storages’ Database Storage:.
I haven’t used it yet, but it looks awesome and I’m going to start using it as soon as I Post My Answer.
- [Django]-Django-cors-headers not work
- [Django]-Paginating the results of a Django forms POST request
- [Django]-Get request data in Django form
Source:stackexchange.com