Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #10918 -- Ensure that the search widget on a raw_id_admin 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.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15657 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b5b5ba6cd9179372cead3e6d19f732285e80b799 1 parent 0b53d31
Russell Keith-Magee authored February 26, 2011
4  django/contrib/admin/views/main.py
@@ -52,8 +52,6 @@ def __init__(self, request, model, list_display, list_display_links, list_filter
52 52
         self.params = dict(request.GET.items())
53 53
         if PAGE_VAR in self.params:
54 54
             del self.params[PAGE_VAR]
55  
-        if TO_FIELD_VAR in self.params:
56  
-            del self.params[TO_FIELD_VAR]
57 55
         if ERROR_FLAG in self.params:
58 56
             del self.params[ERROR_FLAG]
59 57
 
@@ -173,7 +171,7 @@ def get_query_set(self):
173 171
 
174 172
         qs = self.root_query_set
175 173
         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):
177 175
             if i in lookup_params:
178 176
                 del lookup_params[i]
179 177
         for key, value in lookup_params.items():
10  tests/regressiontests/admin_views/tests.py
@@ -1694,6 +1694,16 @@ def test_search_on_sibling_models(self):
1694 1694
         # confirm the search returned 1 object
1695 1695
         self.assertContains(response, "\n1 recommendation\n")
1696 1696
 
  1697
+    def test_with_fk_to_field(self):
  1698
+        """Ensure that the to_field GET parameter is preserved when a search
  1699
+        is performed. Refs #10918.
  1700
+        """
  1701
+        from django.contrib.admin.views.main import TO_FIELD_VAR
  1702
+        response = self.client.get('/test_admin/admin/auth/user/?q=joe&%s=username' % TO_FIELD_VAR)
  1703
+        self.assertContains(response, "\n1 user\n")
  1704
+        self.assertContains(response, '<input type="hidden" name="t" value="username"/>')
  1705
+
  1706
+
1697 1707
 class AdminInheritedInlinesTest(TestCase):
1698 1708
     fixtures = ['admin-views-users.xml',]
1699 1709
 

0 notes on commit b5b5ba6

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