1
0
mirror of https://github.com/django/django.git synced 2025-10-25 06:36:07 +00:00

[1.10.x] Fixed #26917 -- Fixed crash in disabled ModelChoiceFields.

Partially reverted refs #25532 to fix a regression in Django 1.10.
This reintroduces a crash for disabled forms.JSONField (refs #26949),
however, that issue is also present on Django 1.9.

Thanks Ryan Schave for the test.

Backport of a5f85d891b from master
This commit is contained in:
Tim Graham
2016-07-25 14:04:39 -04:00
parent d53e3c1e07
commit 3744fc1666
3 changed files with 19 additions and 13 deletions

View File

@@ -1499,6 +1499,21 @@ class ModelChoiceFieldTests(TestCase):
'<label><input name="foo" type="radio" value="" /> ---------</label>'
)
def test_disabled_modelchoicefield(self):
class ModelChoiceForm(forms.ModelForm):
author = forms.ModelChoiceField(Author.objects.all(), disabled=True)
class Meta:
model = Book
fields = ['author']
book = Book.objects.create(author=Writer.objects.create(name='Test writer'))
form = ModelChoiceForm({}, instance=book)
self.assertEqual(
form.errors['author'],
['Select a valid choice. That choice is not one of the available choices.']
)
class ModelMultipleChoiceFieldTests(TestCase):
def setUp(self):