Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #10918 -- Ensure that the search widget on a raw_id_adm…

…in uses the right field name when the ForeignKey has a to_field definition. Thanks to David Cramer for the report, Collin Anderson for the fix, and Julien Phalip for the test.

Backport of r15657 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15659 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 120d01c20b3c2deada995e671f3f918aa1d808ce 1 parent 3a31023
Russell Keith-Magee authored February 26, 2011
4  django/contrib/admin/views/main.py
@@ -54,8 +54,6 @@ def __init__(self, request, model, list_display, list_display_links, list_filter
54 54
         self.params = dict(request.GET.items())
55 55
         if PAGE_VAR in self.params:
56 56
             del self.params[PAGE_VAR]
57  
-        if TO_FIELD_VAR in self.params:
58  
-            del self.params[TO_FIELD_VAR]
59 57
         if ERROR_FLAG in self.params:
60 58
             del self.params[ERROR_FLAG]
61 59
 
@@ -167,7 +165,7 @@ def get_ordering(self):
167 165
     def get_query_set(self):
168 166
         qs = self.root_query_set
169 167
         lookup_params = self.params.copy() # a dictionary of the query string
170  
-        for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR):
  168
+        for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR, TO_FIELD_VAR):
171 169
             if i in lookup_params:
172 170
                 del lookup_params[i]
173 171
         for key, value in lookup_params.items():
10  tests/regressiontests/admin_views/tests.py
@@ -1556,6 +1556,16 @@ def test_search_on_sibling_models(self):
1556 1556
         # confirm the search returned 1 object
1557 1557
         self.assertContains(response, "\n1 recommendation\n")
1558 1558
 
  1559
+    def test_with_fk_to_field(self):
  1560
+        """Ensure that the to_field GET parameter is preserved when a search
  1561
+        is performed. Refs #10918.
  1562
+        """
  1563
+        from django.contrib.admin.views.main import TO_FIELD_VAR
  1564
+        response = self.client.get('/test_admin/admin/auth/user/?q=joe&%s=username' % TO_FIELD_VAR)
  1565
+        self.assertContains(response, "\n1 user\n")
  1566
+        self.assertContains(response, '<input type="hidden" name="t" value="username"/>')
  1567
+
  1568
+
1559 1569
 class AdminInheritedInlinesTest(TestCase):
1560 1570
     fixtures = ['admin-views-users.xml',]
1561 1571
 

0 notes on commit 120d01c

Please sign in to comment.
Something went wrong with that request. Please try again.