Add compat util for DecimalValidator

This commit is contained in:
José Padilla 2015-10-29 06:42:16 -04:00
parent 6f6f794be5
commit 41d1e42e9c
2 changed files with 7 additions and 1 deletions

View File

@ -185,6 +185,11 @@ if django.VERSION >= (1, 8):
else:
DurationField = duration_string = parse_duration = None
try:
# DecimalValidator is unavailable in Django < 1.9
from django.core.validators import DecimalValidator
except ImportError:
DecimalValidator = None
def set_rollback():
if hasattr(transaction, 'set_rollback'):

View File

@ -8,6 +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.validators import UniqueValidator
NUMERIC_FIELD_TYPES = (
@ -132,7 +133,7 @@ def get_field_kwargs(field_name, model_field):
if isinstance(model_field, models.DecimalField):
validator_kwarg = [
validator for validator in validator_kwarg
if not isinstance(validator, validators.DecimalValidator)
if DecimalValidator and not isinstance(validator, DecimalValidator)
]
# Ensure that max_length is passed explicitly as a keyword arg,