#NEWLINE# def get_ordering( self ) : #NEWLINE# #INDENT# ( lookup_opts , params ) = ( self . lookup_opts , self . params ) #NEWLINE# ordering = ( self . model_admin . ordering or lookup_opts . ordering or [ ( '-' + lookup_opts . pk . name ) ] ) #NEWLINE# if ordering [ 0 ] . startswith ( '-' ) : #NEWLINE# #INDENT# ( order_field , order_type ) = ( ordering [ 0 ] [ 1 : ] , 'desc' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( order_field , order_type ) = ( ordering [ 0 ] , 'asc' ) #NEWLINE# #UNINDENT# if ( ORDER_VAR in params ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# field_name = self . list_display [ int ( params [ ORDER_VAR ] ) ] #NEWLINE# try : #NEWLINE# #INDENT# f = lookup_opts . get_field ( field_name ) #NEWLINE# #UNINDENT# except models . FieldDoesNotExist : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if callable ( field_name ) : #NEWLINE# #INDENT# attr = field_name #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( self . model_admin , field_name ) : #NEWLINE# #INDENT# attr = getattr ( self . model_admin , field_name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# attr = getattr ( self . model , field_name ) #NEWLINE# #UNINDENT# #UNINDENT# order_field = attr . admin_order_field #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# order_field = f . name #NEWLINE# #UNINDENT# #UNINDENT# except ( IndexError , ValueError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( ( ORDER_TYPE_VAR in params ) and ( params [ ORDER_TYPE_VAR ] in ( 'asc' , 'desc' ) ) ) : #NEWLINE# #INDENT# order_type = params [ ORDER_TYPE_VAR ] #NEWLINE# #UNINDENT# return ( order_field , order_type )