mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-23 01:57:00 +03:00
Use text area for JSON fields and indent JSON
This commit is contained in:
parent
11d8e4df88
commit
7a0bd1c4d1
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user