def build_instance(Model, data, db):
 obj = Model(**data)
 if ((obj.pk is None) and hasattr(Model, 'natural_key') and hasattr(Model._default_manager, 'get_by_natural_key')):
  natural_key = obj.natural_key()
  try:
   obj.pk = Model._default_manager.db_manager(db).get_by_natural_key(*natural_key).pk
  except Model.DoesNotExist:
   pass
 return obj

def build_instance ( Model , data , db ) : obj = Model ( ** data ) if ( ( obj . pk is None ) and hasattr ( Model , 'natural_key' ) and hasattr ( Model . _default_manager , 'get_by_natural_key' ) ) : natural_key = obj . natural_key ( ) try : obj . pk = Model . _default_manager . db_manager ( db ) . get_by_natural_key ( * natural_key ) . pk except Model . DoesNotExist : pass return obj
build a model instance .