def model_to_ctype(val):
 if isinstance(val, Model):
  val = {'pk': val.pk, 'ctype': ContentType.objects.get_for_model(val).pk}
 return val

def model_to_ctype ( val ) : if isinstance ( val , Model ) : val = { 'pk' : val . pk , 'ctype' : ContentType . objects . get_for_model ( val ) . pk } return val
converts values that are instance of model to a dictionary with enough information to retrieve the instance back later .