From fa2a3de6ede10b005fc2c1d23f4cffb53eaec425 Mon Sep 17 00:00:00 2001 From: Rodrigo Vieira Date: Wed, 22 Apr 2026 18:53:27 -0300 Subject: Fixed #10919 -- Added delete_confirmation_max_display to ModelAdmin. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new ModelAdmin.delete_confirmation_max_display attribute allows limiting the number of related objects shown on the delete confirmation page. When the limit is reached, a "…and N more objects." message is shown. The feature relies on a new truncated_unordered_list template filter added to django.contrib.admin.templatetags.admin_filters. Thanks Jacob Tyler Walls for the review and guidance, Tobias McNulty for the report, and terminator14 for the solution suggested. --- tests/modeladmin/test_checks.py | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/modeladmin/test_checks.py') diff --git a/tests/modeladmin/test_checks.py b/tests/modeladmin/test_checks.py index c493148eb9..496e46e8b0 100644 --- a/tests/modeladmin/test_checks.py +++ b/tests/modeladmin/test_checks.py @@ -1020,6 +1020,50 @@ class ListMaxShowAllCheckTests(CheckTestCase): self.assertIsValid(TestModelAdmin, ValidationTestModel) +class DeleteConfirmationMaxObjectsCheckTests(CheckTestCase): + def test_not_integer(self): + class TestModelAdmin(ModelAdmin): + delete_confirmation_max_display = "hello" + + self.assertIsInvalid( + TestModelAdmin, + ValidationTestModel, + ( + "The value of " + "'delete_confirmation_max_display'" + " must be a non-negative integer or None." + ), + "admin.E131", + ) + + def test_negative_integer(self): + class TestModelAdmin(ModelAdmin): + delete_confirmation_max_display = -1 + + self.assertIsInvalid( + TestModelAdmin, + ValidationTestModel, + ( + "The value of " + "'delete_confirmation_max_display'" + " must be a non-negative integer or None." + ), + "admin.E131", + ) + + def test_valid_case(self): + class TestModelAdmin(ModelAdmin): + delete_confirmation_max_display = 100 + + self.assertIsValid(TestModelAdmin, ValidationTestModel) + + def test_valid_none(self): + class TestModelAdmin(ModelAdmin): + delete_confirmation_max_display = None + + self.assertIsValid(TestModelAdmin, ValidationTestModel) + + class SearchFieldsCheckTests(CheckTestCase): def test_not_iterable(self): class TestModelAdmin(ModelAdmin): -- cgit v1.3