diff options
| author | Tom Carrick <tom@carrick.eu> | 2023-04-04 15:11:11 +0100 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2024-02-05 21:42:04 -0300 |
| commit | 4ade8386ebfeb7a781dc2b62542c1cf5f8b9ddaf (patch) | |
| tree | 97263c4f927ad797883bba77db95c6dee6041df4 /tests/admin_utils | |
| parent | 3580b47ed31ec85ae89b13618f36bb463e97acc8 (diff) | |
Fixed #10743 -- Allowed lookups for related fields in ModelAdmin.list_display.
Co-authored-by: Alex Garcia <me@alexoteiza.com>
Co-authored-by: Natalia <124304+nessita@users.noreply.github.com>
Co-authored-by: Nina Menezes <https://github.com/nmenezes0>
Diffstat (limited to 'tests/admin_utils')
| -rw-r--r-- | tests/admin_utils/tests.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/admin_utils/tests.py b/tests/admin_utils/tests.py index 067b47198d..56d46324e0 100644 --- a/tests/admin_utils/tests.py +++ b/tests/admin_utils/tests.py @@ -137,6 +137,7 @@ class UtilsTests(SimpleTestCase): (simple_function, SIMPLE_FUNCTION), ("test_from_model", article.test_from_model()), ("non_field", INSTANCE_ATTRIBUTE), + ("site__domain", SITE_NAME), ) mock_admin = MockModelAdmin() @@ -294,6 +295,17 @@ class UtilsTests(SimpleTestCase): self.assertEqual(label_for_field(lambda x: "nothing", Article), "--") self.assertEqual(label_for_field("site_id", Article), "Site id") + # The correct name and attr are returned when `__` is in the field name. + self.assertEqual(label_for_field("site__domain", Article), "Site domain") + self.assertEqual( + label_for_field("site__domain", Article, return_attr=True), + ("Site domain", Site._meta.get_field("domain")), + ) + + def test_label_for_field_failed_lookup(self): + msg = "Unable to lookup 'site__unknown' on Article" + with self.assertRaisesMessage(AttributeError, msg): + label_for_field("site__unknown", Article) class MockModelAdmin: @admin.display(description="not Really the Model") |
