[Backport] Fixes CharField behaviour and introduces proper validation for ModelField
parent
1c5557f330
commit
a3f88db4d1
|
@ -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