Move JSONField import out of compat.py

This commit is contained in:
Levi Payne 2017-10-04 20:57:52 -04:00
parent 99d120b2e4
commit a22b47fb5f
3 changed files with 11 additions and 10 deletions

View File

@ -115,14 +115,6 @@ def _resolve_model(obj):
raise ValueError("{0} is not a Django model".format(obj)) raise ValueError("{0} is not a Django model".format(obj))
# 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) # coreapi is optional (Note that uritemplate is a dependency of coreapi)
try: try:
import coreapi import coreapi

View File

@ -27,7 +27,6 @@ from django.utils import six, timezone
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.compat import JSONField as ModelJSONField
from rest_framework.compat import set_many, unicode_to_repr from rest_framework.compat import set_many, unicode_to_repr
from rest_framework.exceptions import ErrorDetail, ValidationError from rest_framework.exceptions import ErrorDetail, ValidationError
from rest_framework.fields import get_error_detail, set_value from rest_framework.fields import get_error_detail, set_value
@ -51,6 +50,11 @@ try:
except ImportError: except ImportError:
postgres_fields = None postgres_fields = None
try:
from django.contrib.postgres.fields import JSONField as ModelJSONField
except ImportError:
ModelJSONField = None
# Note: We do the following so that users of the framework can use this style: # Note: We do the following so that users of the framework can use this style:
# #

View File

@ -8,9 +8,14 @@ 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, JSONField from rest_framework.compat import DecimalValidator
from rest_framework.validators import UniqueValidator from rest_framework.validators import UniqueValidator
try:
from django.contrib.postgres.fields import JSONField
except ImportError:
JSONField = None
NUMERIC_FIELD_TYPES = ( NUMERIC_FIELD_TYPES = (
models.IntegerField, models.FloatField, models.DecimalField models.IntegerField, models.FloatField, models.DecimalField
) )