Use text area for JSON fields and indent JSON

This commit is contained in:
Dave Allan 2017-04-26 12:00:32 -04:00
parent 11d8e4df88
commit 7a0bd1c4d1
2 changed files with 3 additions and 3 deletions

View File

@ -8,7 +8,7 @@ from django.core import validators
from django.db import models
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
NUMERIC_FIELD_TYPES = (
@ -88,7 +88,7 @@ def get_field_kwargs(field_name, model_field):
if decimal_places is not None:
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'}
if isinstance(model_field, models.AutoField) or not model_field.editable:

View File

@ -85,7 +85,7 @@ class BoundField(object):
class JSONBoundField(BoundField):
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)