I'm using Django 1.8.
The documentation on writing validators has an example of a function-based validator. It also says the following on using a class:
You can also use a class with a
__call__()
method for more complex or configurable validators. RegexValidator, for example, uses this technique. If a class-based validator is used in the validators model field option, you should make sure it is serializable by the migration framework by addingdeconstruct()
and__eq__()
methods.
- What are the pros/cons of class-based against function-based validators?
- What is
__call__()
used for, and how is it used? - What is
deconstruct()
used for, and how is it used? - What is
__eq__()
used for, and how is it used?
An example would be helpful. A full answer may also be worth submitting to be in the official documentation.
Thanks!