aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/utils
diff options
context:
space:
mode:
authorTom Christie2014-10-08 16:09:37 +0100
committerTom Christie2014-10-08 16:09:37 +0100
commit14ae52a24e93063f77c6010269bf9cd3316627fe (patch)
treec87bede7775b8eaf8fa33ff9e8028575a47fe26c /rest_framework/utils
parent28f3b314f12cbff33c55602c2c5f5f5cce956171 (diff)
downloaddjango-rest-framework-14ae52a24e93063f77c6010269bf9cd3316627fe.tar.bz2
More gradual deprecation
Diffstat (limited to 'rest_framework/utils')
-rw-r--r--rest_framework/utils/field_mapping.py22
-rw-r--r--rest_framework/utils/model_meta.py4
2 files changed, 13 insertions, 13 deletions
diff --git a/rest_framework/utils/field_mapping.py b/rest_framework/utils/field_mapping.py
index fd6da699..6db37146 100644
--- a/rest_framework/utils/field_mapping.py
+++ b/rest_framework/utils/field_mapping.py
@@ -71,6 +71,17 @@ def get_field_kwargs(field_name, model_field):
if model_field.help_text:
kwargs['help_text'] = model_field.help_text
+ max_digits = getattr(model_field, 'max_digits', None)
+ if max_digits is not None:
+ kwargs['max_digits'] = max_digits
+
+ decimal_places = getattr(model_field, 'decimal_places', None)
+ if decimal_places is not None:
+ kwargs['decimal_places'] = decimal_places
+
+ if isinstance(model_field, models.TextField):
+ kwargs['style'] = {'type': 'textarea'}
+
if isinstance(model_field, models.AutoField) or not model_field.editable:
# If this field is read-only, then return early.
# Further keyword arguments are not valid.
@@ -86,9 +97,6 @@ def get_field_kwargs(field_name, model_field):
kwargs['choices'] = model_field.flatchoices
return kwargs
- if isinstance(model_field, models.TextField):
- kwargs['style'] = {'type': 'textarea'}
-
if model_field.null and not isinstance(model_field, models.NullBooleanField):
kwargs['allow_null'] = True
@@ -171,14 +179,6 @@ def get_field_kwargs(field_name, model_field):
validator = UniqueValidator(queryset=model_field.model._default_manager)
validator_kwarg.append(validator)
- max_digits = getattr(model_field, 'max_digits', None)
- if max_digits is not None:
- kwargs['max_digits'] = max_digits
-
- decimal_places = getattr(model_field, 'decimal_places', None)
- if decimal_places is not None:
- kwargs['decimal_places'] = decimal_places
-
if validator_kwarg:
kwargs['validators'] = validator_kwarg
diff --git a/rest_framework/utils/model_meta.py b/rest_framework/utils/model_meta.py
index b6c41174..7a95bcdd 100644
--- a/rest_framework/utils/model_meta.py
+++ b/rest_framework/utils/model_meta.py
@@ -107,8 +107,8 @@ def get_field_info(model):
related=relation.model,
to_many=True,
has_through_model=(
- hasattr(relation.field.rel, 'through') and
- not relation.field.rel.through._meta.auto_created
+ (getattr(relation.field.rel, 'through', None) is not None)
+ and not relation.field.rel.through._meta.auto_created
)
)