old_contents: import json
  from django.db import models
  
  
  SEQUENCE_FORMATS = (
      ('text', 'text'),
      ('json', 'json'),
  )
  
  
  class DjangoPillowCheckpoint(models.Model):
  
      checkpoint_id = models.CharField(primary_key=True, max_length=100)
      sequence = models.TextField()
      timestamp = models.DateTimeField(auto_now=True)
      old_sequence = models.TextField(null=True, blank=True)
      sequence_format = models.CharField(max_length=20, choices=SEQUENCE_FORMATS, default='text')
  
      @property
      def wrapped_sequence(self):
          if self.sequence_format == 'json':
              seq = json.loads(self.sequence)
              # deconstruct tuple keys
              marshaled_seq = {}
              for key, val in seq.items():
                  topic, partition = key.split(',')
                  marshaled_seq[(topic, int(partition))] = val
              return marshaled_seq
          else:
              return self.sequence
  
      class Meta:
          app_label = "pillowtop"
  
      @staticmethod
      def to_dict(instance):
          """
          Return a dictionary that looks like the Couch-based implementation of these.
          """
          return {
              '_id': instance.checkpoint_id,
              'seq': instance.sequence,
              'timestamp': instance.timestamp.isoformat(),
              'old_seq': instance.old_sequence,
          }
  
      @staticmethod
      def from_dict(checkpoint_dict):
          """
          Create a checkpoint from a dictionary that looks like the
          Couch-based implementation of these.
          """
          return DjangoPillowCheckpoint(
              checkpoint_id=checkpoint_dict['pk'],
              sequence=checkpoint_dict['seq'],
              old_sequence=checkpoint_dict.get('old_seq', None)
          )
  
new_contents: import json
  from django.db import models
  from kafka.common import TopicAndPartition
  
  SEQUENCE_FORMATS = (
      ('text', 'text'),
      ('json', 'json'),
  )
  
  
  class DjangoPillowCheckpoint(models.Model):
  
      checkpoint_id = models.CharField(primary_key=True, max_length=100)
      sequence = models.TextField()
      timestamp = models.DateTimeField(auto_now=True)
      old_sequence = models.TextField(null=True, blank=True)
      sequence_format = models.CharField(max_length=20, choices=SEQUENCE_FORMATS, default='text')
  
      @property
      def wrapped_sequence(self):
          if self.sequence_format == 'json':
              seq = json.loads(self.sequence)
              # deconstruct tuple keys
              marshaled_seq = {}
              for key, val in seq.items():
                  topic, partition = key.split(',')
                  marshaled_seq[TopicAndPartition(topic, int(partition))] = val
              return marshaled_seq
          else:
              return self.sequence
  
      class Meta:
          app_label = "pillowtop"
  
      @staticmethod
      def to_dict(instance):
          """
          Return a dictionary that looks like the Couch-based implementation of these.
          """
          return {
              '_id': instance.checkpoint_id,
              'seq': instance.sequence,
              'timestamp': instance.timestamp.isoformat(),
              'old_seq': instance.old_sequence,
          }
  
      @staticmethod
      def from_dict(checkpoint_dict):
          """
          Create a checkpoint from a dictionary that looks like the
          Couch-based implementation of these.
          """
          return DjangoPillowCheckpoint(
              checkpoint_id=checkpoint_dict['pk'],
              sequence=checkpoint_dict['seq'],
              old_sequence=checkpoint_dict.get('old_seq', None)
          )
  
subject: use named tuple for convenience