Add a note about Django constraints for custom validation

This commit is contained in:
Radoslav Georgiev 2019-10-27 17:23:28 +02:00
parent c986c1e6c8
commit 3c40f63aca

View File

@ -167,6 +167,7 @@ We have few general rules for custom validations & model properties / methods:
* If the custom validation depends only on the **non-relational model fields**, define it in `clean` and call `full_clean` in `save`.
* If the custom validation is more complex & **spans relationships**, do it in the service that creates the model.
* It's OK to combine both `clean` and additional validation in the `service`.
* As proposed in [this issue](https://github.com/HackSoftware/Django-Styleguide/issues/22), if you can do a validation using [Django's constraints](https://docs.djangoproject.com/en/2.2/ref/models/constraints/), then you should aim for that. Less code to write.
### Properties