code: def serialize_instance(instance):
      
      ret = dict([(k, v)
                  for k, v in instance.__dict__.items()
                  if not k.startswith('_')])
      return json.loads(json.dumps(ret, cls=DjangoJSONEncoder))
docs: Since Django 1.6 items added to the session are no longer pickled,
      but JSON encoded by default. We are storing partially complete models
      in the session (user, account, token, ...). We cannot use standard
      Django serialization, as these are models are not "complete" yet.
      Serialization will start complaining about missing relations et al.