diff options
author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-02-05 09:17:32 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-02-05 09:21:38 +0100 |
commit | 1d5fb35e6a23c0670f3a128802a1776c8c7deaa8 (patch) | |
tree | d7be153f73ec30887ccfe3d8c78b63a1cc61fcc2 /tests/model_forms | |
parent | 335c9c94acf263901fb023404408880245b0c4b4 (diff) | |
download | django-1d5fb35e6a23c0670f3a128802a1776c8c7deaa8.tar.gz |
Refs #26813 -- Added test for ModelChoiceField.choices when using RadioSelect widget.
Diffstat (limited to 'tests/model_forms')
-rw-r--r-- | tests/model_forms/tests.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 8259b3b8bd..a4e1ee1183 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 |