From 1d5fb35e6a23c0670f3a128802a1776c8c7deaa8 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 5 Feb 2020 09:17:32 +0100 Subject: [PATCH] Refs #26813 -- Added test for ModelChoiceField.choices when using RadioSelect widget. --- tests/model_forms/tests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 8259b3b8bd6..a4e1ee11831 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -259,6 +259,20 @@ class ModelFormBaseTest(TestCase): award = form.save() self.assertIsNone(award.character) + def test_blank_foreign_key_with_radio(self): + class BookForm(forms.ModelForm): + class Meta: + model = Book + fields = ['author'] + widgets = {'author': forms.RadioSelect()} + + writer = Writer.objects.create(name='Joe Doe') + form = BookForm() + self.assertEqual(list(form.fields['author'].choices), [ + ('', '---------'), + (writer.pk, 'Joe Doe'), + ]) + def test_save_blank_false_with_required_false(self): """ A ModelForm with a model with a field set to blank=False and the form