old_contents: import base64
  import bz2
  import json
  
  from django.db import models
  from django.db.models.fields.subclassing import Creator
  
  
  class PatchedSubFieldBase(type):
      """These next bits all related to a bug in Django custom fields which
      prevent autodoc from succeeding. Once the associated fix is in our
      version of Django, we can uncomment the metaclass line and delete
      PatchedCreator and make_contrib
      https://code.djangoproject.com/ticket/12568"""
      class PatchedCreator(Creator):
          def __get__(self, obj, type=None):
              if obj is None:
                  return self
              return obj.__dict__[self.field.name]
  
      def __new__(cls, name, bases, attrs):
          new_class = super(PatchedSubFieldBase, cls).__new__(cls, name, bases,
                                                              attrs)
  
          def contrib(self, cls, name):
              if attrs.get('contrib_to_class'):
                  attrs.contrib_to_class(self, cls, name)
              else:
                  super(new_class, self).contribute_to_class(cls, name)
              setattr(cls, self.name, PatchedSubFieldBase.PatchedCreator(self))
          new_class.contribute_to_class = contrib
          return new_class
  
  
  class CompressedJSONField(models.TextField):
      """We store a lot of data redundantly. This field type makes each copy
      much smaller. We need this when inserting hundreds of regtext nodes and
      layer nodes into relational databases, lest we blow the packet size limit
      """
      __metaclass__ = PatchedSubFieldBase
  
      # Now returning to regularly scheduled class definition
      def to_python(self, value):
          if not isinstance(value, str) and not isinstance(value, unicode):
              return value
  
          encoding, content = value.split('$', 1)
          encoding = reversed(encoding)
          for encoding_type in encoding:
              if encoding_type == 'j':
                  content = json.loads(content)
              elif encoding_type == '6':
                  content = base64.decodestring(content)
              elif encoding_type == 'b':
                  content = bz2.decompress(content)
          return content
  
      def get_prep_value(self, value):
          value = json.dumps(value)
          encoding = 'j'
  
          if len(value) > 1000:  # somewhat arbitrary length to start compression
              # check if compressing is smaller
              compressed = base64.encodestring(bz2.compress(value))
              if len(compressed) < len(value):
                  encoding += 'b6'
                  value = compressed
  
          return encoding + '$' + value
  
      def __get__(self, instance, instance_type=None):
          if instance is None:
              return self
  
new_contents: import base64
  import bz2
  import json
  
  from django.db import models
  import six
  
  
  class CompressedJSONField(models.TextField):
      """We store a lot of data redundantly. This field type makes each copy
      much smaller. We need this when inserting hundreds of regtext nodes and
      layer nodes into relational databases, lest we blow the packet size limit
      """
      # Now returning to regularly scheduled class definition
      def to_python(self, value):
          """Convert the string (from the database) into a JSON dictionary"""
          if not isinstance(value, six.text_type):
              return value
  
          encoding, content = value.split('$', 1)
          encoding = reversed(encoding)
          for encoding_type in encoding:
              if encoding_type == 'j':
                  content = json.loads(content)
              elif encoding_type == '6':
                  content = base64.decodestring(content)
              elif encoding_type == 'b':
                  content = bz2.decompress(content)
          return content
  
      def from_db_value(self, value, expression, connection, context):
          """Satisfies Django 1.8's custom field types requirements."""
          return self.to_python(value)
  
      def get_prep_value(self, value):
          """Convert from a JSON dictionary to a database string"""
          value = json.dumps(value)
          encoding = 'j'
  
          if len(value) > 1000:  # somewhat arbitrary length to start compression
              # check if compressing is smaller
              compressed = base64.encodestring(bz2.compress(value))
              if len(compressed) < len(value):
                  encoding += 'b6'
                  value = compressed
  
          return encoding + '$' + value
  
subject: Remove workaround for Django bug