diff options
| author | Tom Christie | 2014-10-08 16:09:37 +0100 |
|---|---|---|
| committer | Tom Christie | 2014-10-08 16:09:37 +0100 |
| commit | 14ae52a24e93063f77c6010269bf9cd3316627fe (patch) | |
| tree | c87bede7775b8eaf8fa33ff9e8028575a47fe26c /rest_framework/utils/field_mapping.py | |
| parent | 28f3b314f12cbff33c55602c2c5f5f5cce956171 (diff) | |
| download | django-rest-framework-14ae52a24e93063f77c6010269bf9cd3316627fe.tar.bz2 | |
More gradual deprecation
Diffstat (limited to 'rest_framework/utils/field_mapping.py')
| -rw-r--r-- | rest_framework/utils/field_mapping.py | 22 |
1 files changed, 11 insertions, 11 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 |
