mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 04:20:12 +03:00
Update postgres compat
JSONField now always available.
This commit is contained in:
parent
efccb0d1c4
commit
0d78453fa5
|
@ -115,23 +115,13 @@ def _resolve_model(obj):
|
|||
raise ValueError("{0} is not a Django model".format(obj))
|
||||
|
||||
|
||||
|
||||
# TODO: Remove
|
||||
# contrib.postgres only supported from 1.8 onwards.
|
||||
# django.contrib.postgres requires psycopg2
|
||||
try:
|
||||
from django.contrib.postgres import fields as postgres_fields
|
||||
except ImportError:
|
||||
postgres_fields = None
|
||||
|
||||
|
||||
# TODO: Remove
|
||||
# JSONField is only supported from 1.9 onwards
|
||||
try:
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
except ImportError:
|
||||
JSONField = None
|
||||
|
||||
|
||||
# coreapi is optional (Note that uritemplate is a dependency of coreapi)
|
||||
try:
|
||||
import coreapi
|
||||
|
|
|
@ -27,7 +27,6 @@ from django.utils import six, timezone
|
|||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from rest_framework.compat import JSONField as ModelJSONField
|
||||
from rest_framework.compat import postgres_fields, set_many, unicode_to_repr
|
||||
from rest_framework.exceptions import ErrorDetail, ValidationError
|
||||
from rest_framework.fields import get_error_detail, set_value
|
||||
|
@ -861,8 +860,6 @@ class ModelSerializer(Serializer):
|
|||
}
|
||||
if ModelDurationField is not None:
|
||||
serializer_field_mapping[ModelDurationField] = DurationField
|
||||
if ModelJSONField is not None:
|
||||
serializer_field_mapping[ModelJSONField] = JSONField
|
||||
serializer_related_field = PrimaryKeyRelatedField
|
||||
serializer_related_to_field = SlugRelatedField
|
||||
serializer_url_field = HyperlinkedIdentityField
|
||||
|
@ -1532,6 +1529,7 @@ if postgres_fields:
|
|||
|
||||
ModelSerializer.serializer_field_mapping[postgres_fields.HStoreField] = CharMappingField
|
||||
ModelSerializer.serializer_field_mapping[postgres_fields.ArrayField] = ListField
|
||||
ModelSerializer.serializer_field_mapping[postgres_fields.JSONField] = JSONField
|
||||
|
||||
|
||||
class HyperlinkedModelSerializer(ModelSerializer):
|
||||
|
|
|
@ -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, JSONField
|
||||
from rest_framework.compat import DecimalValidator, postgres_fields
|
||||
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) or (JSONField and isinstance(model_field, JSONField)):
|
||||
if isinstance(model_field, models.TextField) or (postgres_fields and isinstance(model_field, postgres_fields.JSONField)):
|
||||
kwargs['style'] = {'base_template': 'textarea.html'}
|
||||
|
||||
if isinstance(model_field, models.AutoField) or not model_field.editable:
|
||||
|
|
Loading…
Reference in New Issue
Block a user