Skip to content

Commit

Permalink
[1.2.X] Fixed #10918 -- Ensure that the search widget on a raw_id_adm…
Browse files Browse the repository at this point in the history
…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
freakboy3742 committed Feb 26, 2011
1 parent 3a31023 commit 120d01c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 1 addition & 3 deletions django/contrib/admin/views/main.py
Expand Up @@ -54,8 +54,6 @@ def __init__(self, request, model, list_display, list_display_links, list_filter
self.params = dict(request.GET.items()) self.params = dict(request.GET.items())
if PAGE_VAR in self.params: if PAGE_VAR in self.params:
del self.params[PAGE_VAR] del self.params[PAGE_VAR]
if TO_FIELD_VAR in self.params:
del self.params[TO_FIELD_VAR]
if ERROR_FLAG in self.params: if ERROR_FLAG in self.params:
del self.params[ERROR_FLAG] del self.params[ERROR_FLAG]


Expand Down Expand Up @@ -167,7 +165,7 @@ def get_ordering(self):
def get_query_set(self): def get_query_set(self):
qs = self.root_query_set qs = self.root_query_set
lookup_params = self.params.copy() # a dictionary of the query string lookup_params = self.params.copy() # a dictionary of the query string
for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR): for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR, TO_FIELD_VAR):
if i in lookup_params: if i in lookup_params:
del lookup_params[i] del lookup_params[i]
for key, value in lookup_params.items(): for key, value in lookup_params.items():
Expand Down
10 changes: 10 additions & 0 deletions tests/regressiontests/admin_views/tests.py
Expand Up @@ -1556,6 +1556,16 @@ def test_search_on_sibling_models(self):
# confirm the search returned 1 object # confirm the search returned 1 object
self.assertContains(response, "\n1 recommendation\n") self.assertContains(response, "\n1 recommendation\n")


def test_with_fk_to_field(self):
"""Ensure that the to_field GET parameter is preserved when a search
is performed. Refs #10918.
"""
from django.contrib.admin.views.main import TO_FIELD_VAR
response = self.client.get('/test_admin/admin/auth/user/?q=joe&%s=username' % TO_FIELD_VAR)
self.assertContains(response, "\n1 user\n")
self.assertContains(response, '<input type="hidden" name="t" value="username"/>')


class AdminInheritedInlinesTest(TestCase): class AdminInheritedInlinesTest(TestCase):
fixtures = ['admin-views-users.xml',] fixtures = ['admin-views-users.xml',]


Expand Down

0 comments on commit 120d01c

Please sign in to comment.