#NEWLINE# def test_fk_with_to_field( self ) : #NEWLINE# #INDENT# "\n        A filter on a FK respects the FK's to_field attribute (#17972).\n        " #NEWLINE# modeladmin = EmployeeAdmin ( Employee , site ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Employee , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . jack , self . john ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ ( - 1 ) ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'department' ) #NEWLINE# choices = list ( filterspec . choices ( changelist ) ) #NEWLINE# self . assertEqual ( choices [ 0 ] [ 'display' ] , 'All' ) #NEWLINE# self . assertEqual ( choices [ 0 ] [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( choices [ 0 ] [ 'query_string' ] , '?' ) #NEWLINE# self . assertEqual ( choices [ 1 ] [ 'display' ] , 'Development' ) #NEWLINE# self . assertEqual ( choices [ 1 ] [ 'selected' ] , False ) #NEWLINE# self . assertEqual ( choices [ 1 ] [ 'query_string' ] , '?department__code__exact=DEV' ) #NEWLINE# self . assertEqual ( choices [ 2 ] [ 'display' ] , 'Design' ) #NEWLINE# self . assertEqual ( choices [ 2 ] [ 'selected' ] , False ) #NEWLINE# self . assertEqual ( choices [ 2 ] [ 'query_string' ] , '?department__code__exact=DSN' ) #NEWLINE# request = self . request_factory . get ( '/' , { #NEWLINE# #INDENT# 'department__code__exact' : 'DEV' , #NEWLINE# #UNINDENT# } ) #NEWLINE# changelist = self . get_changelist ( request , Employee , modeladmin ) #NEWLINE# queryset = changelist . get_queryset ( request ) #NEWLINE# self . assertEqual ( list ( queryset ) , [ self . john ] ) #NEWLINE# filterspec = changelist . get_filters ( request ) [ 0 ] [ ( - 1 ) ] #NEWLINE# self . assertEqual ( force_text ( filterspec . title ) , 'department' ) #NEWLINE# choices = list ( filterspec . choices ( changelist ) ) #NEWLINE# self . assertEqual ( choices [ 0 ] [ 'display' ] , 'All' ) #NEWLINE# self . assertEqual ( choices [ 0 ] [ 'selected' ] , False ) #NEWLINE# self . assertEqual ( choices [ 0 ] [ 'query_string' ] , '?' ) #NEWLINE# self . assertEqual ( choices [ 1 ] [ 'display' ] , 'Development' ) #NEWLINE# self . assertEqual ( choices [ 1 ] [ 'selected' ] , True ) #NEWLINE# self . assertEqual ( queryset [ 1 ] [ 'query_string' ] , '?department__code__exact=DEV' ) #NEWLINE# self . assertEqual ( choices [ 2 ] [ 'display' ] , 'Design' ) #NEWLINE# self . assertEqual ( choices [ 2 ] [ 'selected' ] , False ) #NEWLINE# self . assertEqual ( choices [ 2 ] [ 'query_string' ] , '?department__code__exact=DSN' )