summaryrefslogtreecommitdiff
path: root/tests/admin_changelist/tests.py
diff options
context:
space:
mode:
authorSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-11-04 16:09:55 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-11-05 09:06:14 +0100
commit5fa4ccab7e42e86fa4a0681d21bd1326c9c5eac3 (patch)
treeba4a1d65c8b3e47e5c7c02971851a64b63a44c13 /tests/admin_changelist/tests.py
parent5bd58058116d2e6f07b72881218548fd9904167e (diff)
Refs #26001 -- Handled relationship exact lookups in ModelAdmin.search_fields.
Diffstat (limited to 'tests/admin_changelist/tests.py')
-rw-r--r--tests/admin_changelist/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index a823a72f7d..0be6a54ed4 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -879,6 +879,28 @@ class ChangeListTests(TestCase):
cl = model_admin.get_changelist_instance(request)
self.assertCountEqual(cl.queryset, expected_result)
+ def test_search_with_exact_lookup_relationship_field(self):
+ child = Child.objects.create(name="I am a child", age=11)
+ grandchild = GrandChild.objects.create(name="I am a grandchild", parent=child)
+ model_admin = GrandChildAdmin(GrandChild, custom_site)
+
+ request = self.factory.get("/", data={SEARCH_VAR: "'I am a child'"})
+ request.user = self.superuser
+ cl = model_admin.get_changelist_instance(request)
+ self.assertCountEqual(cl.queryset, [grandchild])
+ for search_term, expected_result in [
+ ("11", [grandchild]),
+ ("'I am a child'", [grandchild]),
+ ("1", []),
+ ("A", []),
+ ("random", []),
+ ]:
+ request = self.factory.get("/", data={SEARCH_VAR: search_term})
+ request.user = self.superuser
+ with self.subTest(search_term=search_term):
+ cl = model_admin.get_changelist_instance(request)
+ self.assertCountEqual(cl.queryset, expected_result)
+
def test_no_distinct_for_m2m_in_list_filter_without_params(self):
"""
If a ManyToManyField is in list_filter but isn't in any lookup params,