diff options
| author | Yuri Prezument | 2014-01-05 15:58:46 +0200 |
|---|---|---|
| committer | Yuri Prezument | 2014-01-12 10:53:54 +0200 |
| commit | 6e622d644c9b55b905e24497f0fb818d557fd970 (patch) | |
| tree | c0e8925e313887ec67092bf63a5fcb2f6dba4aca /rest_framework/fields.py | |
| parent | e88e3c6ae163029f0fe564dd214235ab350dbfc9 (diff) | |
| download | django-rest-framework-6e622d644c9b55b905e24497f0fb818d557fd970.tar.bz2 | |
CharField - add allow_null argument
Diffstat (limited to 'rest_framework/fields.py')
| -rw-r--r-- | rest_framework/fields.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 22f0120b..16485b41 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -443,8 +443,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)) @@ -452,7 +453,7 @@ class CharField(WritableField): self.validators.append(validators.MaxLengthValidator(max_length)) def from_native(self, value): - if value is None: + if value is None and not self.allow_none: return '' if isinstance(value, six.string_types): return value |
