summaryrefslogtreecommitdiff
path: root/tests/model_forms/test_modelchoicefield.py
diff options
context:
space:
mode:
authorAnnabelle Wiegart <annabelle.wiegart@proton.me>2026-01-18 20:03:28 +0100
committerJacob Walls <jacobtylerwalls@gmail.com>2026-04-22 17:06:29 -0400
commit63c56cda133a85a158502891c40465bc0331d3d9 (patch)
tree04380903d14307b71416b2e048ce4be8361cf0df /tests/model_forms/test_modelchoicefield.py
parentdc467fdc3b5744cec71fab876c23a14013e2510b (diff)
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 <mail@marijkeluttekes.dev>
Diffstat (limited to 'tests/model_forms/test_modelchoicefield.py')
-rw-r--r--tests/model_forms/test_modelchoicefield.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py
index 7f66b5b078..40c625da7c 100644
--- a/tests/model_forms/test_modelchoicefield.py
+++ b/tests/model_forms/test_modelchoicefield.py
@@ -2,6 +2,7 @@ import datetime
from django import forms
from django.core.exceptions import ValidationError
+from django.db.models.utils import get_blank_choice_label
from django.forms.models import ModelChoiceIterator, ModelChoiceIteratorValue
from django.forms.widgets import CheckboxSelectMultiple
from django.template import Context, Template
@@ -24,7 +25,7 @@ class ModelChoiceFieldTests(TestCase):
self.assertEqual(
list(f.choices),
[
- ("", "---------"),
+ ("", get_blank_choice_label()),
(self.c1.pk, "Entertainment"),
(self.c2.pk, "A test"),
(self.c3.pk, "Third"),
@@ -102,7 +103,7 @@ class ModelChoiceFieldTests(TestCase):
self.assertEqual(
list(f.choices),
[
- ("", "---------"),
+ ("", get_blank_choice_label()),
(self.c1.pk, "Entertainment"),
(self.c2.pk, "A test"),
],
@@ -118,7 +119,7 @@ class ModelChoiceFieldTests(TestCase):
self.assertEqual(
list(gen_two),
[
- ("", "---------"),
+ ("", get_blank_choice_label()),
(self.c1.pk, "Entertainment"),
(self.c2.pk, "A test"),
],
@@ -130,7 +131,7 @@ class ModelChoiceFieldTests(TestCase):
self.assertEqual(
list(f.choices),
[
- ("", "---------"),
+ ("", get_blank_choice_label()),
(self.c1.pk, "category Entertainment"),
(self.c2.pk, "category A test"),
(self.c3.pk, "category Third"),
@@ -143,7 +144,7 @@ class ModelChoiceFieldTests(TestCase):
self.assertEqual(
list(f.choices),
[
- ("", "---------"),
+ ("", get_blank_choice_label()),
(self.c1.pk, "Entertainment"),
(self.c2.pk, "A test"),
(self.c3.pk, "Third"),
@@ -154,7 +155,7 @@ class ModelChoiceFieldTests(TestCase):
self.assertEqual(
list(f.choices),
[
- ("", "---------"),
+ ("", get_blank_choice_label()),
(self.c1.pk, "Entertainment"),
(self.c2.pk, "A test"),
(self.c3.pk, "Third"),
@@ -174,6 +175,7 @@ class ModelChoiceFieldTests(TestCase):
self.assertIs(bool(f.choices), True)
def test_choices_radio_blank(self):
+ blank_choice = [("", get_blank_choice_label())]
choices = [
(self.c1.pk, "Entertainment"),
(self.c2.pk, "A test"),
@@ -190,7 +192,7 @@ class ModelChoiceFieldTests(TestCase):
)
self.assertEqual(
list(f.choices),
- [("", "---------")] + choices if blank else choices,
+ (blank_choice + choices if blank else choices),
)
def test_deepcopies_widget(self):
@@ -424,7 +426,7 @@ class ModelChoiceFieldTests(TestCase):
self.assertCountEqual(
list(f.choices),
[
- ("", "---------"),
+ ("", get_blank_choice_label()),
(self.c1.pk, "Entertainment"),
(self.c2.pk, "A test"),
(self.c3.pk, "Third"),