Refs -- Added test for ModelChoiceField.choices when using RadioSelect widget.
@@ -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
