mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #26813 -- Prevented empty choice in ModelChoiceField with RadioSelect for fields with blank=False.
This commit is contained in:
committed by
Mariusz Felisiak
parent
1d5fb35e6a
commit
da79ee472d
@@ -139,6 +139,26 @@ class ModelChoiceFieldTests(TestCase):
|
||||
Category.objects.all().delete()
|
||||
self.assertIs(bool(f.choices), True)
|
||||
|
||||
def test_choices_radio_blank(self):
|
||||
choices = [
|
||||
(self.c1.pk, 'Entertainment'),
|
||||
(self.c2.pk, 'A test'),
|
||||
(self.c3.pk, 'Third'),
|
||||
]
|
||||
categories = Category.objects.all()
|
||||
for widget in [forms.RadioSelect, forms.RadioSelect()]:
|
||||
for blank in [True, False]:
|
||||
with self.subTest(widget=widget, blank=blank):
|
||||
f = forms.ModelChoiceField(
|
||||
categories,
|
||||
widget=widget,
|
||||
blank=blank,
|
||||
)
|
||||
self.assertEqual(
|
||||
list(f.choices),
|
||||
[('', '---------')] + choices if blank else choices,
|
||||
)
|
||||
|
||||
def test_deepcopies_widget(self):
|
||||
class ModelChoiceForm(forms.Form):
|
||||
category = forms.ModelChoiceField(Category.objects.all())
|
||||
|
||||
Reference in New Issue
Block a user