def ctype_to_model(val):
 if (isinstance(val, dict) and ('pk' in val) and ('ctype' in val)):
  ctype = ContentType.objects.get_for_id(val['ctype'])
  ModelClass = ctype.model_class()
  val = ModelClass.objects.get(pk=val['pk'])
 return val

def ctype_to_model ( val ) : if ( isinstance ( val , dict ) and ( 'pk' in val ) and ( 'ctype' in val ) ) : ctype = ContentType . objects . get_for_id ( val [ 'ctype' ] ) ModelClass = ctype . model_class ( ) val = ModelClass . objects . get ( pk = val [ 'pk' ] ) return val
converts back the instance saved by model_to_ctype function .