Hi all, during a sprint at PyCON 2008 I wrote first simple version of model validation.
Main features:
- model fields can define list of validators (kwarg validators) - validator is a function that accepts one argument and throws django.core.validation.validationError if anything doesn't look right
- models now have a validate method that
- call the validation for fields
- can be overridden to allow for custom validation
- raises django.core.validation.validationError if anything goes amiss
- formfields' clean method has been deprecated and split into two - to_python and validate
- to_python does the type coersion, throws django.core.validation.TypeCoersionError
- validate doesnt return anything, just raises an exception
- new kwarg validators allows for passing validators to formfields as well
- form method clean has been renamed to validate and also doesn't return anything.
- hooks for validation individual fields on form should now be named validate_FIELD_NAME and take the value to validate as only parameter
Steps that remain to be done:
- verify how much code has been broken by this
- clean the code, update comments
- add more tests for the new behavior
- add documentation
- add validation to formsets to validate for unique and unique_together across all the forms in the formset
- allow to turn some of the validation off ???
- unique(_together) for performance reasons