From 3744fc1666c41aeb4ed44f31605bafdb413b42bc Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Mon, 25 Jul 2016 14:04:39 -0400 Subject: [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 a5f85d891b51d7ceb4f9e422e3e4f5c741062288 from master --- tests/model_forms/tests.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/model_forms') diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 2f96fcec30..e18b19dcac 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -1499,6 +1499,21 @@ class ModelChoiceFieldTests(TestCase): '' ) + 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): -- cgit v1.3