diff --git a/src/woo_publications/logging/admin.py b/src/woo_publications/logging/admin.py index 2a4d65e8..103a6c97 100644 --- a/src/woo_publications/logging/admin.py +++ b/src/woo_publications/logging/admin.py @@ -44,6 +44,7 @@ class TimelineLogProxyAdmin(admin.ModelAdmin): search_fields = ( "extra_data__acting_user__identifier", "extra_data__acting_user__display_name", + "extra_data___cached_object_repr", ) list_select_related = ("content_type", "user") date_hierarchy = "timestamp" diff --git a/src/woo_publications/logging/tests/test_admin.py b/src/woo_publications/logging/tests/test_admin.py index 53d6795d..4873306c 100644 --- a/src/woo_publications/logging/tests/test_admin.py +++ b/src/woo_publications/logging/tests/test_admin.py @@ -222,6 +222,18 @@ def test_search_behaviour(self): "identifier": "testsuite", "display_name": "Automated tests", }, + "_cached_object_repr": "foobar", + }, + ) + # broken audit log entry + TimelineLogProxy.objects.create( + extra_data={ + "event": Events.read, + "acting_user": { + "identifier": None, + "display_name": None, + }, + "_cached_object_repr": None, }, ) @@ -241,6 +253,13 @@ def test_search_behaviour(self): self.assertNotContains(response, "1234") self.assertContains(response, "testsuite") + with self.subTest("search on cached_object_repr"): + response = self.app.get(self.list_url, {"q": "foobar"}) + + self.assertEqual(response.status_code, 200) + self.assertNumLogsDisplayed(response, 1) + self.assertContains(response, "foobar") + def test_no_excessive_queries_for_content_object(self): # create a 100 records to fill the admin - can't use bulk create because that # skips the save method :)