#NEWLINE# def names_to_path( self , names , opts , allow_many = True , fail_on_missing = False ) : #NEWLINE# #INDENT# "\n        Walks the list of names and turns them into PathInfo tuples. Note that\n        a single name in 'names' can generate multiple PathInfos (m2m for\n        example).\n\n        'names' is the path of names to travel, 'opts' is the model Options we\n        start the name resolving from, 'allow_many' is as for setup_joins().\n        If fail_on_missing is set to True, then a name that can't be resolved\n        will generate a FieldError.\n\n        Returns a list of PathInfo tuples. In addition returns the final field\n        (the last used join field), and target (which is a field guaranteed to\n        contain the same value as the final field). Finally, the method returns\n        those names that weren't found (which are likely transforms and the\n        final lookup).\n        " #NEWLINE# ( path , names_with_path ) = ( [ ] , [ ] ) #NEWLINE# for ( pos , name ) in enumerate ( names ) : #NEWLINE# #INDENT# cur_names_with_path = ( name , [ ] ) #NEWLINE# if ( name == 'pk' ) : #NEWLINE# #INDENT# name = opts . pk . name #NEWLINE# #UNINDENT# field = None #NEWLINE# try : #NEWLINE# #INDENT# field = opts . get_field ( name ) #NEWLINE# #UNINDENT# except FieldDoesNotExist : #NEWLINE# #INDENT# if ( name in self . annotation_select ) : #NEWLINE# #INDENT# field = self . annotation_select [ name ] . output_field #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( pos == 0 ) : #NEWLINE# #INDENT# for rel in opts . related_objects : #NEWLINE# #INDENT# if ( ( name == rel . related_model . _meta . model_name ) and ( rel . related_name == rel . related_model . _meta . default_related_name ) ) : #NEWLINE# #INDENT# related_name = rel . related_name #NEWLINE# field = opts . get_field ( related_name ) #NEWLINE# warnings . warn ( ( "Query lookup '%s' is deprecated in favor of Meta.default_related_name '%s'." % ( name , related_name ) ) , RemovedInDjango20Warning , 2 ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( field is not None ) : #NEWLINE# #INDENT# if ( field . is_relation and ( not field . related_model ) ) : #NEWLINE# #INDENT# raise FieldError ( ( 'Field %r does not generate an automatic reverse relation and therefore cannot be used for reverse querying. If it is a GenericForeignKey, consider adding a GenericRelation.' % name ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# model = field . model . _meta . concrete_model #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# model = None #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# pos -= 1 #NEWLINE# if ( ( pos == ( - 1 ) ) or fail_on_missing ) : #NEWLINE# #INDENT# field_names = list ( get_field_names_from_opts ( opts ) ) #NEWLINE# available = sorted ( ( field_names + list ( self . annotation_select ) ) ) #NEWLINE# raise FieldError ( ( 'Cannot resolve keyword %r into field. Choices are: %s' % ( name , ', ' . join ( available ) ) ) ) #NEWLINE# #UNINDENT# break #NEWLINE# #UNINDENT# if ( model is not opts . model ) : #NEWLINE# #INDENT# proxied_model = opts . concrete_model #NEWLINE# for int_model in opts . get_base_chain ( model ) : #NEWLINE# #INDENT# if ( int_model is proxied_model ) : #NEWLINE# #INDENT# opts = int_model . _meta #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# final_field = allow_many . parents [ int_model ] #NEWLINE# targets = ( final_field . remote_field . get_related_field ( ) , ) #NEWLINE# opts = int_model . _meta #NEWLINE# path . append ( PathInfo ( final_field . model . _meta , opts , targets , final_field , False , True ) ) #NEWLINE# cur_names_with_path [ 1 ] . append ( PathInfo ( final_field . model . _meta , opts , targets , final_field , False , True ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if hasattr ( field , 'get_path_info' ) : #NEWLINE# #INDENT# pathinfos = field . get_path_info ( ) #NEWLINE# if ( not allow_many ) : #NEWLINE# #INDENT# for ( inner_pos , p ) in enumerate ( pathinfos ) : #NEWLINE# #INDENT# if p . m2m : #NEWLINE# #INDENT# cur_names_with_path [ 1 ] . extend ( pathinfos [ 0 : ( inner_pos + 1 ) ] ) #NEWLINE# names_with_path . append ( cur_names_with_path ) #NEWLINE# raise MultiJoin ( ( pos + 1 ) , names_with_path ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# last = pathinfos [ ( - 1 ) ] #NEWLINE# path . extend ( pathinfos ) #NEWLINE# final_field = last . join_field #NEWLINE# opts = last . to_opts #NEWLINE# targets = last . target_fields #NEWLINE# cur_names_with_path [ 1 ] . extend ( pathinfos ) #NEWLINE# names_with_path . append ( cur_names_with_path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# final_field = field #NEWLINE# targets = ( field , ) #NEWLINE# if ( fail_on_missing and ( ( pos + 1 ) != len ( names ) ) ) : #NEWLINE# #INDENT# raise FieldError ( ( "Cannot resolve keyword %r into field. Join on '%s' not permitted." % ( names [ ( pos + 1 ) ] , name ) ) ) #NEWLINE# #UNINDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return ( path , final_field , targets , names [ ( pos + 1 ) : ] )