'A filter on a FK respects the FK\'s to_field attribute (#17972).'

def test_fk_with_to_field(self):

    modeladmin = EmployeeAdmin(Employee, site)
    request = self.request_factory.get('/', {})
    changelist = self.get_changelist(request, Employee, modeladmin)
    queryset = changelist.get_queryset(request)
    self.assertEqual(list(queryset), [self.jack, self.john])
    filterspec = changelist.get_filters(request)[0][(-1)]
    self.assertEqual(filterspec.title, 'department')
    choices = list(filterspec.choices(changelist))
    self.assertEqual(choices[0]['display'], 'All')
    self.assertIs(choices[0]['selected'], True)
    self.assertEqual(choices[0]['query_string'], '?')
    self.assertEqual(choices[1]['display'], 'Development')
    self.assertIs(choices[1]['selected'], False)
    self.assertEqual(choices[1]['query_string'], '?department__code__exact=DEV')
    self.assertEqual(choices[2]['display'], 'Design')
    self.assertIs(choices[2]['selected'], False)
    self.assertEqual(choices[2]['query_string'], '?department__code__exact=DSN')
    request = self.request_factory.get('/', {'department__code__exact': 'DEV'})
    changelist = self.get_changelist(request, Employee, modeladmin)
    queryset = changelist.get_queryset(request)
    self.assertEqual(list(queryset), [self.john])
    filterspec = changelist.get_filters(request)[0][(-1)]
    self.assertEqual(filterspec.title, 'department')
    choices = list(filterspec.choices(changelist))
    self.assertEqual(choices[0]['display'], 'All')
    self.assertIs(choices[0]['selected'], False)
    self.assertEqual(choices[0]['query_string'], '?')
    self.assertEqual(choices[1]['display'], 'Development')
    self.assertIs(choices[1]['selected'], True)
    self.assertEqual(choices[1]['query_string'], '?department__code__exact=DEV')
    self.assertEqual(choices[2]['display'], 'Design')
    self.assertIs(choices[2]['selected'], False)
    self.assertEqual(choices[2]['query_string'], '?department__code__exact=DSN')
