diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
index 635330f..d441136 100644
a
|
b
|
class ChangeList(object):
|
254 | 254 | return "%s__icontains" % field_name |
255 | 255 | |
256 | 256 | if self.search_fields and self.query: |
| 257 | constructed_fields = [construct_search(str(field_name)) |
| 258 | for field_name in self.search_fields] |
257 | 259 | for bit in self.query.split(): |
258 | | or_queries = [models.Q(**{construct_search(str(field_name)): bit}) for field_name in self.search_fields] |
| 260 | or_queries = [models.Q(**{field_name: bit}) |
| 261 | for field_name in constructed_fields] |
259 | 262 | qs = qs.filter(reduce(operator.or_, or_queries)) |
260 | 263 | if not use_distinct: |
261 | | for search_field in self.search_fields: |
| 264 | for search_field in constructed_fields: |
262 | 265 | field_name = search_field.split('__', 1)[0] |
263 | 266 | f = self.lookup_opts.get_field_by_name(field_name)[0] |
264 | 267 | if hasattr(f, 'rel') and isinstance(f.rel, models.ManyToManyRel): |
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index 9ac99cc..3b44f94 100644
a
|
b
|
class PersonAdmin(admin.ModelAdmin):
|
258 | 258 | list_display = ('name', 'gender', 'alive') |
259 | 259 | list_editable = ('gender', 'alive') |
260 | 260 | list_filter = ('gender',) |
261 | | search_fields = (u'name',) |
| 261 | search_fields = ('^name',) |
262 | 262 | ordering = ["id"] |
263 | 263 | save_as = True |
264 | 264 | |
… |
… |
class Recommendation(Title):
|
445 | 445 | recommender = models.ForeignKey(Recommender) |
446 | 446 | |
447 | 447 | class RecommendationAdmin(admin.ModelAdmin): |
448 | | search_fields = ('titletranslation__text', 'recommender__titletranslation__text',) |
| 448 | search_fields = ('=titletranslation__text', '=recommender__titletranslation__text',) |
449 | 449 | |
450 | 450 | class Collector(models.Model): |
451 | 451 | name = models.CharField(max_length=100) |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 6be07b4..545e7c4 100644
a
|
b
|
class AdminViewListEditable(TestCase):
|
1470 | 1470 | |
1471 | 1471 | "_save": "Save", |
1472 | 1472 | } |
1473 | | self.client.post('/test_admin/admin/admin_views/person/?q=mauchly', data) |
| 1473 | self.client.post('/test_admin/admin/admin_views/person/?q=john', data) |
1474 | 1474 | |
1475 | 1475 | self.assertEqual(Person.objects.get(name="John Mauchly").alive, False) |
1476 | 1476 | |
… |
… |
class AdminViewListEditable(TestCase):
|
1680 | 1680 | |
1681 | 1681 | |
1682 | 1682 | class AdminSearchTest(TestCase): |
1683 | | fixtures = ['admin-views-users','multiple-child-classes'] |
| 1683 | fixtures = ['admin-views-users', 'multiple-child-classes', |
| 1684 | 'admin-views-person'] |
1684 | 1685 | |
1685 | 1686 | def setUp(self): |
1686 | 1687 | self.client.login(username='super', password='secret') |
… |
… |
class AdminSearchTest(TestCase):
|
1702 | 1703 | response = self.client.get('/test_admin/admin/auth/user/?q=joe&%s=username' % TO_FIELD_VAR) |
1703 | 1704 | self.assertContains(response, "\n1 user\n") |
1704 | 1705 | self.assertContains(response, '<input type="hidden" name="t" value="username"/>') |
1705 | | |
| 1706 | |
| 1707 | def test_exact_matches(self): |
| 1708 | response = self.client.get('/test_admin/admin/admin_views/recommendation/?q=bar') |
| 1709 | # confirm the search returned 1 object |
| 1710 | self.assertContains(response, "\n1 recommendation\n") |
| 1711 | |
| 1712 | response = self.client.get('/test_admin/admin/admin_views/recommendation/?q=ba') |
| 1713 | # confirm the search returned 1 object |
| 1714 | self.assertContains(response, "\n0 recommendations\n") |
| 1715 | |
| 1716 | def test_beginning_matches(self): |
| 1717 | response = self.client.get('/test_admin/admin/admin_views/person/?q=Gui') |
| 1718 | # confirm the search returned 1 object |
| 1719 | self.assertContains(response, "\n1 person\n") |
| 1720 | self.assertContains(response, "Guido") |
| 1721 | |
| 1722 | response = self.client.get('/test_admin/admin/admin_views/person/?q=uido') |
| 1723 | # confirm the search returned 1 object |
| 1724 | self.assertContains(response, "\n0 persons\n") |
| 1725 | self.assertNotContains(response, "Guido") |
1706 | 1726 | |
1707 | 1727 | class AdminInheritedInlinesTest(TestCase): |
1708 | 1728 | fixtures = ['admin-views-users.xml',] |