I think Django's model validation is a little inconvenient for those models that don't use built-in ModelForm, though not knowing why.
Firstly, full_clean()
needs called manually.
Note that full_clean() will not be called automatically when you call your model’s save() method, nor as a result of ModelForm validation.In the case of ModelForm validation, Model.clean_fields(), Model.clean(), and Model.validate_unique() are all called individually.You’ll need to call full_clean manually when you want to run one-step model validation for your own manually created models.
Secondly, validators
are used in built-in ModelForm
.
Note that validators will not be run automatically when you save a model, but if you are using a ModelForm, it will run your validators on any fields that are included in your form.
There are great demands when you need to do data validation before saving data into databases. And obviously I'd prefer to make it in model, rather than views. So, are there any good ideas to implement this gracefully in Django 1.5?