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/model_fields/test_booleanfield.py | 5 ++++- tests/model_fields/tests.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'tests/model_fields') diff --git a/tests/model_fields/test_booleanfield.py b/tests/model_fields/test_booleanfield.py index 30eb009eb7..d0ed6e86cc 100644 --- a/tests/model_fields/test_booleanfield.py +++ b/tests/model_fields/test_booleanfield.py @@ -1,6 +1,7 @@ from django import forms from django.core.exceptions import ValidationError from django.db import IntegrityError, models, transaction +from django.db.models.utils import get_blank_choice_label from django.test import SimpleTestCase, TestCase from .models import BooleanModel, FksToBooleans, NullBooleanModel @@ -48,7 +49,9 @@ class BooleanFieldTests(TestCase): """ choices = [(1, "Si"), (2, "No")] f = models.BooleanField(choices=choices) - self.assertEqual(f.formfield().choices, [("", "---------")] + choices) + self.assertEqual( + f.formfield().choices, [("", get_blank_choice_label())] + choices + ) def test_nullbooleanfield_formfield(self): f = models.BooleanField(null=True) diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index b27c07a92f..fa7436343a 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -391,7 +391,10 @@ class GetChoicesTests(SimpleTestCase): def test_lazy_strings_not_evaluated(self): lazy_func = lazy(lambda x: 0 / 0, int) # raises ZeroDivisionError if evaluated. f = models.CharField(choices=[(lazy_func("group"), [("a", "A"), ("b", "B")])]) - self.assertEqual(f.get_choices(include_blank=True)[0], ("", "---------")) + self.assertEqual( + f.get_choices(include_blank=True)[0], + ("", models.utils.get_blank_choice_label()), + ) class GetChoicesOrderingTests(TestCase): -- cgit v1.3