#NEWLINE# def get_query_set( self ) : #NEWLINE# #INDENT# qs = self . root_query_set #NEWLINE# lookup_params = self . params . copy ( ) #NEWLINE# for i in ( ALL_VAR , ORDER_VAR , ORDER_TYPE_VAR , SEARCH_VAR , IS_POPUP_VAR ) : #NEWLINE# #INDENT# if ( i in lookup_params ) : #NEWLINE# #INDENT# del lookup_params [ i ] #NEWLINE# #UNINDENT# #UNINDENT# for ( key , value ) in lookup_params . items ( ) : #NEWLINE# #INDENT# if ( not isinstance ( key , str ) ) : #NEWLINE# #INDENT# del lookup_params [ key ] #NEWLINE# lookup_params [ smart_str ( key ) ] = value #NEWLINE# #UNINDENT# if key . endswith ( '__in' ) : #NEWLINE# #INDENT# value = value . split ( ',' ) #NEWLINE# lookup_params [ key ] = value #NEWLINE# #UNINDENT# if key . endswith ( '__isnull' ) : #NEWLINE# #INDENT# if ( value . lower ( ) in ( '' , 'false' ) ) : #NEWLINE# #INDENT# value = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# value = True #NEWLINE# #UNINDENT# lookup_params [ key ] = value #NEWLINE# #UNINDENT# if ( not self . model_admin . lookup_allowed ( key , value ) ) : #NEWLINE# #INDENT# raise SuspiciousOperation ( ( 'Filtering by %s not allowed' % key ) ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# qs = qs . filter ( ** lookup_params ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# raise IncorrectLookupParameters #NEWLINE# #UNINDENT# if ( not qs . query . select_related ) : #NEWLINE# #INDENT# if self . list_select_related : #NEWLINE# #INDENT# qs = qs . select_related ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for field_name in self . list_display : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# f = self . lookup_opts . get_field ( field_name ) #NEWLINE# #UNINDENT# except models . FieldDoesNotExist : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( f . rel , models . ManyToOneRel ) : #NEWLINE# #INDENT# qs = qs . select_related ( ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if self . order_field : #NEWLINE# #INDENT# qs = qs . order_by ( ( '%s%s' % ( ( ( ( self . order_type == 'desc' ) and '-' ) or '' ) , self . order_field ) ) ) #NEWLINE# #UNINDENT# def construct_search( field_name ) : #NEWLINE# #INDENT# if field_name . startswith ( '^' ) : #NEWLINE# #INDENT# return ( '%s__istartswith' % field_name [ 1 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if field_name . startswith ( '=' ) : #NEWLINE# #INDENT# return ( '%s__iexact' % field_name [ 1 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if field_name . startswith ( '@' ) : #NEWLINE# #INDENT# return ( '%s__search' % field_name [ 1 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '%s__icontains' % field_name ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( self . search_fields and self . query ) : #NEWLINE# #INDENT# for bit in self . query . split ( ) : #NEWLINE# #INDENT# or_queries = [ models . Q ( ** { #NEWLINE# #INDENT# construct_search ( str ( field_name ) ) : bit , #NEWLINE# #UNINDENT# } ) for field_name in self . search_fields ] #NEWLINE# qs = qs . filter ( reduce ( operator . or_ , or_queries ) ) #NEWLINE# #UNINDENT# for field_name in self . search_fields : #NEWLINE# #INDENT# if ( '__' in field_name ) : #NEWLINE# #INDENT# qs = qs . distinct ( ) #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return qs