diff options
| author | Xavier Ordoquy | 2014-05-01 08:01:38 +0200 |
|---|---|---|
| committer | Xavier Ordoquy | 2014-05-01 08:01:38 +0200 |
| commit | 7b4463f73983e36f228e6af0ff8c921d4698a9b3 (patch) | |
| tree | c26fd01425a3754e65a0b2c48694ca734278745f /rest_framework/fields.py | |
| parent | 2aca69a94601858a462060bc55154c812f70fb91 (diff) | |
| parent | c9e6f31166ebccc5c3bf2f27e12a6d6c87f5cf22 (diff) | |
| download | django-rest-framework-7b4463f73983e36f228e6af0ff8c921d4698a9b3.tar.bz2 | |
Merge remote-tracking branch 'reference/2.4.0' into feature/pytest
Conflicts:
rest_framework/runtests/urls.py
tests/test_response.py
tox.ini
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 8cdc5551..8eaf763d 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -18,12 +18,14 @@ from django.conf import settings from django.db.models.fields import BLANK_CHOICE_DASH from django.http import QueryDict from django.forms import widgets +from django.utils import timezone from django.utils.encoding import is_protected_type from django.utils.translation import ugettext_lazy as _ from django.utils.datastructures import SortedDict +from django.utils.dateparse import parse_date, parse_datetime, parse_time from rest_framework import ISO_8601 from rest_framework.compat import ( - timezone, parse_date, parse_datetime, parse_time, BytesIO, six, smart_text, + BytesIO, six, smart_text, force_text, is_non_str_iterable ) from rest_framework.settings import api_settings @@ -260,13 +262,6 @@ class WritableField(Field): validators=[], error_messages=None, widget=None, default=None, blank=None): - # 'blank' is to be deprecated in favor of 'required' - if blank is not None: - warnings.warn('The `blank` keyword argument is deprecated. ' - 'Use the `required` keyword argument instead.', - DeprecationWarning, stacklevel=2) - required = not(blank) - super(WritableField, self).__init__(source=source, label=label, help_text=help_text) self.read_only = read_only @@ -460,8 +455,9 @@ class CharField(WritableField): type_label = 'string' form_field_class = forms.CharField - def __init__(self, max_length=None, min_length=None, *args, **kwargs): + def __init__(self, max_length=None, min_length=None, allow_none=False, *args, **kwargs): self.max_length, self.min_length = max_length, min_length + self.allow_none = allow_none super(CharField, self).__init__(*args, **kwargs) if min_length is not None: self.validators.append(validators.MinLengthValidator(min_length)) @@ -469,7 +465,9 @@ class CharField(WritableField): self.validators.append(validators.MaxLengthValidator(max_length)) def from_native(self, value): - if isinstance(value, six.string_types) or value is None: + if value is None and not self.allow_none: + return '' + if isinstance(value, six.string_types): return value return smart_text(value) |
