Ticket #10918: 10918_admin_search_missing_fk_to_field.diff

File 10918_admin_search_missing_fk_to_field.diff, 1.9 KB (added by Julien Phalip, 14 years ago)
  • django/contrib/admin/views/main.py

    diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
    index d0f0350..635330f 100644
    a b class ChangeList(object):  
    5252        self.params = dict(request.GET.items())
    5353        if PAGE_VAR in self.params:
    5454            del self.params[PAGE_VAR]
    55         if TO_FIELD_VAR in self.params:
    56             del self.params[TO_FIELD_VAR]
    5755        if ERROR_FLAG in self.params:
    5856            del self.params[ERROR_FLAG]
    5957
    class ChangeList(object):  
    173171
    174172        qs = self.root_query_set
    175173        lookup_params = self.params.copy() # a dictionary of the query string
    176         for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR):
     174        for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR, TO_FIELD_VAR):
    177175            if i in lookup_params:
    178176                del lookup_params[i]
    179177        for key, value in lookup_params.items():
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 7782f9e..ed7da4a 100644
    a b class AdminSearchTest(TestCase):  
    16941694        # confirm the search returned 1 object
    16951695        self.assertContains(response, "\n1 recommendation\n")
    16961696
     1697    def test_with_fk_to_field(self):
     1698        """ Ensure that the to_field GET parameter is preserved when a search
     1699            is performed.
     1700            Refs #10918.
     1701        """
     1702        from django.contrib.admin.views.main import TO_FIELD_VAR
     1703        response = self.client.get('/test_admin/admin/auth/user/?q=joe&%s=username' % TO_FIELD_VAR)
     1704        self.assertContains(response, "\n1 user\n")
     1705        self.assertContains(response, '<input type="hidden" name="t" value="username"/>')
     1706       
    16971707class AdminInheritedInlinesTest(TestCase):
    16981708    fixtures = ['admin-views-users.xml',]
    16991709
Back to Top