summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlexander Yermakov <mannavard1611@gmail.com>2016-07-26 08:18:08 -0400
committerTim Graham <timograham@gmail.com>2016-07-27 08:14:14 -0400
commit68de48c96328e13d5dbdb1f3006e4a1ca74f3c34 (patch)
tree2f789d5bce2c93e9640d32de703fd30f527a4391
parenta5f85d891b51d7ceb4f9e422e3e4f5c741062288 (diff)
Fixed #26949 -- Fixed crash of disabled forms.JSONField.
-rw-r--r--django/contrib/postgres/forms/jsonb.py2
-rw-r--r--tests/postgres_tests/test_json.py8
2 files changed, 10 insertions, 0 deletions
diff --git a/django/contrib/postgres/forms/jsonb.py b/django/contrib/postgres/forms/jsonb.py
index bd1f175e4b..83a62a8b7c 100644
--- a/django/contrib/postgres/forms/jsonb.py
+++ b/django/contrib/postgres/forms/jsonb.py
@@ -18,6 +18,8 @@ class JSONField(forms.CharField):
widget = forms.Textarea
def to_python(self, value):
+ if self.disabled:
+ return value
if value in self.empty_values:
return None
try:
diff --git a/tests/postgres_tests/test_json.py b/tests/postgres_tests/test_json.py
index 0165cabfd9..b88d103761 100644
--- a/tests/postgres_tests/test_json.py
+++ b/tests/postgres_tests/test_json.py
@@ -260,6 +260,14 @@ class TestFormField(PostgreSQLTestCase):
form_field = model_field.formfield()
self.assertIsInstance(form_field, forms.JSONField)
+ def test_formfield_disabled(self):
+ class JsonForm(Form):
+ name = CharField()
+ jfield = forms.JSONField(disabled=True)
+
+ form = JsonForm({'name': 'xyz', 'jfield': '["bar"]'}, initial={'jfield': ['foo']})
+ self.assertIn('[&quot;foo&quot;]</textarea>', form.as_p())
+
def test_prepare_value(self):
field = forms.JSONField()
self.assertEqual(field.prepare_value({'a': 'b'}), '{"a": "b"}')