Merge pull request #864 from taigaio/Fixes-CharField-behaviour-and-introduces-proper-validation-for-ModelField

Fixes CharField behaviour and introduces proper validation for ModelField
remotes/origin/issue/4795/notification_even_they_are_disabled
David Barragán Merino 2016-10-21 14:15:43 +02:00 committed by GitHub
commit acb758d98f
1 changed files with 8 additions and 2 deletions

View File

@ -467,6 +467,11 @@ class ModelField(WritableField):
"type": self.model_field.get_internal_type() "type": self.model_field.get_internal_type()
} }
def validate(self, value):
super(ModelField, self).validate(value)
if value is None and not self.model_field.null:
raise ValidationError(self.error_messages['invalid'])
##### Typed Fields ##### ##### Typed Fields #####
@ -512,8 +517,9 @@ class CharField(WritableField):
self.validators.append(validators.MaxLengthValidator(max_length)) self.validators.append(validators.MaxLengthValidator(max_length))
def from_native(self, value): def from_native(self, value):
if isinstance(value, six.string_types) or value is None: if value in validators.EMPTY_VALUES:
return value return ""
return smart_text(value) return smart_text(value)
def to_native(self, value): def to_native(self, value):