summaryrefslogtreecommitdiff
path: root/tests/model_forms/tests.py
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2020-02-02 17:30:34 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-05 10:27:01 +0100
commitda79ee472d803963dc3ea81ee67767dc06068aac (patch)
tree6c8ad56c7820dc1fc46cea16fc6250b96d111360 /tests/model_forms/tests.py
parent1d5fb35e6a23c0670f3a128802a1776c8c7deaa8 (diff)
downloaddjango-da79ee472d803963dc3ea81ee67767dc06068aac.tar.gz
Fixed #26813 -- Prevented empty choice in ModelChoiceField with RadioSelect for fields with blank=False.
Diffstat (limited to 'tests/model_forms/tests.py')
-rw-r--r--tests/model_forms/tests.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index a4e1ee1183..0caf6e9bad 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -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