From 63c56cda133a85a158502891c40465bc0331d3d9 Mon Sep 17 00:00:00 2001 From: Annabelle Wiegart Date: Sun, 18 Jan 2026 20:03:28 +0100 Subject: Fixed #35870 -- Made blank choice label in forms more accessible. Added new constant django.db.models.fields.BLANK_CHOICE_LABEL for an accessible and translatable blank choice label in forms. Deprecated django.db.models.fields.BLANK_CHOICE_DASH constant. Added the immediately deprecated transitional setting USE_BLANK_CHOICE_DASH. Co-Authored-By: Marijke Luttekes --- tests/modeladmin/tests.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'tests/modeladmin') diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index 74bbc83efb..5ca7999bf0 100644 --- a/tests/modeladmin/tests.py +++ b/tests/modeladmin/tests.py @@ -18,6 +18,7 @@ from django.contrib.admin.widgets import ( ) from django.contrib.auth.models import User from django.db import models +from django.db.models.utils import get_blank_choice_label from django.forms.widgets import Select from django.test import RequestFactory, SimpleTestCase, TestCase from django.test.utils import isolate_apps @@ -636,7 +637,7 @@ class ModelAdminTests(TestCase): '" % (band2.id, self.band.id), @@ -660,8 +661,8 @@ class ModelAdminTests(TestCase): '" % self.band.id, ) @@ -708,30 +709,31 @@ class ModelAdminTests(TestCase): # ForeignKey widgets in the admin are wrapped with # RelatedFieldWidgetWrapper so they need to be handled properly when # type checking. For Select fields, all of the choices lists have a - # first entry of dashes. + # first entry of a translatable blank choice label. + blank_option = ("", get_blank_choice_label()) cma = ModelAdmin(Concert, self.site) cmafa = cma.get_form(request) self.assertEqual(type(cmafa.base_fields["main_band"].widget.widget), Select) self.assertEqual( list(cmafa.base_fields["main_band"].widget.choices), - [("", "---------"), (self.band.id, "The Doors")], + [blank_option, (self.band.id, "The Doors")], ) self.assertEqual(type(cmafa.base_fields["opening_band"].widget.widget), Select) self.assertEqual( list(cmafa.base_fields["opening_band"].widget.choices), - [("", "---------"), (self.band.id, "The Doors")], + [blank_option, (self.band.id, "The Doors")], ) self.assertEqual(type(cmafa.base_fields["day"].widget), Select) self.assertEqual( list(cmafa.base_fields["day"].widget.choices), - [("", "---------"), (1, "Fri"), (2, "Sat")], + [blank_option, (1, "Fri"), (2, "Sat")], ) self.assertEqual(type(cmafa.base_fields["transport"].widget), Select) self.assertEqual( list(cmafa.base_fields["transport"].widget.choices), - [("", "---------"), (1, "Plane"), (2, "Train"), (3, "Bus")], + [blank_option, (1, "Plane"), (2, "Train"), (3, "Bus")], ) def test_foreign_key_as_radio_field(self): @@ -849,7 +851,7 @@ class ModelAdminTests(TestCase): 'class="related-widget-wrapper" data-model-ref="band">" ) -- cgit v1.3