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.
This commit is contained in:
Tim Graham 2016-07-25 14:04:39 -04:00
parent 0d1218896f
commit a5f85d891b
3 changed files with 19 additions and 13 deletions

View file

@ -1519,6 +1519,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.']
)
def test_modelchoicefield_iterator(self):
"""
Iterator defaults to ModelChoiceIterator and can be overridden with