#NEWLINE# def deferred_to_data( self , target , callback ) : #NEWLINE# #INDENT# '\n        Converts the self.deferred_loading data structure to an alternate data\n        structure, describing the field that *will* be loaded. This is used to\n        compute the columns to select from the database and also by the\n        QuerySet class to work out which fields are being initialised on each\n        model. Models that have all their fields included aren\'t mentioned in\n        the result, only those that have field restrictions in place.\n\n        The "target" parameter is the instance that is populated (in place).\n        The "callback" is a function that is called whenever a (model, field)\n        pair need to be added to "target". It accepts three parameters:\n        "target", and the model and list of fields being added for that model.\n        ' #NEWLINE# ( field_names , defer ) = self . deferred_loading #NEWLINE# if ( not field_names ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# orig_opts = self . get_meta ( ) #NEWLINE# seen = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# must_include = { #NEWLINE# #INDENT# orig_opts . concrete_model : set ( [ orig_opts . pk ] ) , #NEWLINE# #UNINDENT# } #NEWLINE# for field_name in field_names : #NEWLINE# #INDENT# parts = field_name . split ( LOOKUP_SEP ) #NEWLINE# cur_model = self . model #NEWLINE# opts = orig_opts #NEWLINE# for name in parts [ : ( - 1 ) ] : #NEWLINE# #INDENT# old_model = cur_model #NEWLINE# source = opts . get_field_by_name ( name ) [ 0 ] #NEWLINE# if is_reverse_o2o ( source ) : #NEWLINE# #INDENT# cur_model = source . model #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cur_model = source . rel . to #NEWLINE# #UNINDENT# opts = cur_model . _meta #NEWLINE# if ( not is_reverse_o2o ( source ) ) : #NEWLINE# #INDENT# must_include [ old_model ] . add ( source ) #NEWLINE# #UNINDENT# add_to_dict ( must_include , cur_model , callback . pk ) #NEWLINE# #UNINDENT# ( field , model , _ , _ ) = opts . get_field_by_name ( parts [ ( - 1 ) ] ) #NEWLINE# if ( model is None ) : #NEWLINE# #INDENT# model = cur_model #NEWLINE# #UNINDENT# if ( not is_reverse_o2o ( field ) ) : #NEWLINE# #INDENT# add_to_dict ( seen , model , field ) #NEWLINE# #UNINDENT# #UNINDENT# if defer : #NEWLINE# #INDENT# workset = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( model , values ) in six . iteritems ( seen ) : #NEWLINE# #INDENT# for ( field , m ) in model . _meta . get_fields_with_model ( ) : #NEWLINE# #INDENT# if ( field in values ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# add_to_dict ( workset , ( m or model ) , field ) #NEWLINE# #UNINDENT# #UNINDENT# for ( model , values ) in six . iteritems ( must_include ) : #NEWLINE# #INDENT# if ( model in workset ) : #NEWLINE# #INDENT# workset [ model ] . update ( values ) #NEWLINE# #UNINDENT# #UNINDENT# for ( model , values ) in six . iteritems ( workset ) : #NEWLINE# #INDENT# callback ( target , model , values ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for ( model , values ) in six . iteritems ( must_include ) : #NEWLINE# #INDENT# if ( model in seen ) : #NEWLINE# #INDENT# seen [ model ] . update ( values ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# seen [ model ] = values #NEWLINE# #UNINDENT# #UNINDENT# for model in orig_opts . get_parent_list ( ) : #NEWLINE# #INDENT# if ( model not in seen ) : #NEWLINE# #INDENT# seen [ model ] = set ( ) #NEWLINE# #UNINDENT# #UNINDENT# for ( model , values ) in six . iteritems ( seen ) : #NEWLINE# #INDENT# callback ( target , model , values )