#NEWLINE# def query_terms( model , path ) : #NEWLINE# #INDENT# ' Yields QueryTerms of given path starting from given model.\n        - model can be either a regular model or a translatable model\n    ' #NEWLINE# bits = path . split ( '__' ) #NEWLINE# field = None #NEWLINE# for ( depth , bit ) in enumerate ( bits ) : #NEWLINE# #INDENT# if ( bit == 'pk' ) : #NEWLINE# #INDENT# bit = model . _meta . pk . name #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( django . VERSION >= ( 1 , 8 ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# field = model . _meta . get_field . real ( bit ) #NEWLINE# translated = False #NEWLINE# #UNINDENT# except FieldDoesNotExist : #NEWLINE# #INDENT# field = model . _meta . translations_model . _meta . get_field ( bit ) #NEWLINE# translated = True #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# field = model . _meta . get_field ( bit ) #NEWLINE# translated = False #NEWLINE# #UNINDENT# direct = ( ( not field . auto_created ) or getattr ( field , 'db_column' , None ) or getattr ( field , 'attname' , None ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( field , _ , direct , _ ) = model . _meta . get_field_by_name . real ( bit ) #NEWLINE# translated = False #NEWLINE# #UNINDENT# except FieldDoesNotExist : #NEWLINE# #INDENT# ( field , _ , direct , _ ) = model . _meta . translations_model . _meta . get_field_by_name ( bit ) #NEWLINE# translated = True #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# ( field , _ , direct , _ ) = model . _meta . get_field_by_name ( bit ) #NEWLINE# translated = False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except FieldDoesNotExist : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# if direct : #NEWLINE# #INDENT# if field . rel : #NEWLINE# #INDENT# target = field . rel . to . _meta . concrete_model #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# target = None #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# target = ( field . related_model . _meta . concrete_model if ( django . VERSION >= ( 1 , 8 ) ) else field . model . _meta . concrete_model ) #NEWLINE# #UNINDENT# ( yield QueryTerm ( depth = depth , term = bit , model = model , field = field , translated = translated , target = target , many = ( not direct ) ) ) #NEWLINE# if ( target is None ) : #NEWLINE# #INDENT# depth += 1 #NEWLINE# break #NEWLINE# #UNINDENT# model = target #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# for ( depth , bit ) in enumerate ( bits [ depth : ] , depth ) : #NEWLINE# #INDENT# ( yield QueryTerm ( depth = depth , term = bit , model = model , field = None , translated = None , target = None , many = False ) )