def writeDjangoObject(obj, encoder=None):
 s = obj.pk
 if (s is None):
  encoder.writeObject(obj)
  return
 django_objects = getDjangoObjects(encoder.context)
 kls = obj.__class__
 try:
  referenced_object = django_objects.getClassKey(kls, s)
 except KeyError:
  referenced_object = obj
  django_objects.addClassKey(kls, s, obj)
 encoder.writeObject(referenced_object)

def writeDjangoObject ( obj , encoder = None ) : s = obj . pk if ( s is None ) : encoder . writeObject ( obj ) return django_objects = getDjangoObjects ( encoder . context ) kls = obj . __class__ try : referenced_object = django_objects . getClassKey ( kls , s ) except KeyError : referenced_object = obj django_objects . addClassKey ( kls , s , obj ) encoder . writeObject ( referenced_object )
the django orm creates new instances of objects for each db request .