Fixed #26949 -- Fixed crash of disabled forms.JSONField.
This commit is contained in:
parent
a5f85d891b
commit
68de48c963
|
@ -18,6 +18,8 @@ class JSONField(forms.CharField):
|
||||||
widget = forms.Textarea
|
widget = forms.Textarea
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
|
if self.disabled:
|
||||||
|
return value
|
||||||
if value in self.empty_values:
|
if value in self.empty_values:
|
||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -260,6 +260,14 @@ class TestFormField(PostgreSQLTestCase):
|
||||||
form_field = model_field.formfield()
|
form_field = model_field.formfield()
|
||||||
self.assertIsInstance(form_field, forms.JSONField)
|
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('["foo"]</textarea>', form.as_p())
|
||||||
|
|
||||||
def test_prepare_value(self):
|
def test_prepare_value(self):
|
||||||
field = forms.JSONField()
|
field = forms.JSONField()
|
||||||
self.assertEqual(field.prepare_value({'a': 'b'}), '{"a": "b"}')
|
self.assertEqual(field.prepare_value({'a': 'b'}), '{"a": "b"}')
|
||||||
|
|
Loading…
Reference in New Issue