#NEWLINE# def get_model_from_dictionary( model , field_dict ) : #NEWLINE# #INDENT# if isinstance ( model , Model ) : #NEWLINE# #INDENT# model_instance = model #NEWLINE# check_fks = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# model_instance = model ( ) #NEWLINE# check_fks = False #NEWLINE# #UNINDENT# models = [ model_instance ] #NEWLINE# for ( field_name , value ) in field_dict . items ( ) : #NEWLINE# #INDENT# field_obj = model . _meta . fields [ field_name ] #NEWLINE# if isinstance ( value , dict ) : #NEWLINE# #INDENT# rel_obj = field_obj . rel_model #NEWLINE# if check_fks : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# rel_obj = getattr ( model , field_name ) #NEWLINE# #UNINDENT# except models . rel_model . DoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( rel_obj is None ) : #NEWLINE# #INDENT# rel_obj = field_obj . rel_model #NEWLINE# #UNINDENT# #UNINDENT# ( rel_inst , rel_models ) = get_model_from_dictionary ( rel_obj , value ) #NEWLINE# models . extend ( rel_models ) #NEWLINE# setattr ( model_instance , field_name , rel_inst ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# setattr ( model_instance , field_name , field_obj . python_value ( value ) ) #NEWLINE# #UNINDENT# #UNINDENT# return ( model_instance , models )