Commit 7a0bd1c4 by Dave Allan

Use text area for JSON fields and indent JSON

parent 11d8e4df
...@@ -8,7 +8,7 @@ from django.core import validators ...@@ -8,7 +8,7 @@ from django.core import validators
from django.db import models from django.db import models
from django.utils.text import capfirst from django.utils.text import capfirst
from rest_framework.compat import DecimalValidator from rest_framework.compat import DecimalValidator, JSONField
from rest_framework.validators import UniqueValidator from rest_framework.validators import UniqueValidator
NUMERIC_FIELD_TYPES = ( NUMERIC_FIELD_TYPES = (
...@@ -88,7 +88,7 @@ def get_field_kwargs(field_name, model_field): ...@@ -88,7 +88,7 @@ def get_field_kwargs(field_name, model_field):
if decimal_places is not None: if decimal_places is not None:
kwargs['decimal_places'] = decimal_places kwargs['decimal_places'] = decimal_places
if isinstance(model_field, models.TextField): if isinstance(model_field, models.TextField) or (JSONField and isinstance(model_field, JSONField)):
kwargs['style'] = {'base_template': 'textarea.html'} kwargs['style'] = {'base_template': 'textarea.html'}
if isinstance(model_field, models.AutoField) or not model_field.editable: if isinstance(model_field, models.AutoField) or not model_field.editable:
......
...@@ -85,7 +85,7 @@ class BoundField(object): ...@@ -85,7 +85,7 @@ class BoundField(object):
class JSONBoundField(BoundField): class JSONBoundField(BoundField):
def as_form_field(self): def as_form_field(self):
value = json.dumps(self.value) value = json.dumps(self.value, sort_keys=True, indent=4)
return self.__class__(self._field, value, self.errors, self._prefix) return self.__class__(self._field, value, self.errors, self._prefix)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment