Skip to content

Instantly share code, notes, and snippets.

@smclenithan
smclenithan / fields.py
Last active August 29, 2015 14:05
CompressedTextField Django Model Field
# Simple wrapper over the BinaryField. Assumes it is given text and automatically compresses
# and decompresses upon access. Intended as a space saving mechanism on what
# would normally be bulk text that isn't accessed very often.
# Tested on Python3.4 / Django 1.7
from django.db import models
from django.utils.translation import ugettext_lazy as _
import lzma
class CompressedTextField(models.BinaryField, metaclass=models.SubfieldBase):