Merge pull request #864 from taigaio/Fixes-CharField-behaviour-and-introduces-proper-validation-for-ModelField
Fixes CharField behaviour and introduces proper validation for ModelFieldremotes/origin/issue/4795/notification_even_they_are_disabled
commit
acb758d98f
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue