mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +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
@@ -273,6 +273,23 @@ class ModelFormBaseTest(TestCase):
|
||||
(writer.pk, 'Joe Doe'),
|
||||
])
|
||||
|
||||
def test_non_blank_foreign_key_with_radio(self):
|
||||
class AwardForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Award
|
||||
fields = ['character']
|
||||
widgets = {'character': forms.RadioSelect()}
|
||||
|
||||
character = Character.objects.create(
|
||||
username='user',
|
||||
last_action=datetime.datetime.today(),
|
||||
)
|
||||
form = AwardForm()
|
||||
self.assertEqual(
|
||||
list(form.fields['character'].choices),
|
||||
[(character.pk, 'user')],
|
||||
)
|
||||
|
||||
def test_save_blank_false_with_required_false(self):
|
||||
"""
|
||||
A ModelForm with a model with a field set to blank=False and the form
|
||||
|
||||
Reference in New Issue
Block a user