Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraints instead of clean(), full_clean() #22

Closed
mkurnikov opened this issue Sep 10, 2019 · 2 comments
Closed

Constraints instead of clean(), full_clean() #22

mkurnikov opened this issue Sep 10, 2019 · 2 comments

Comments

@mkurnikov
Copy link

What do you think about moving all the logic from custom clean() methods on the model to the db constraints?
https://docs.djangoproject.com/en/2.2/ref/models/constraints/

Yes, some logic is not representable as a constraint, it could be an exception which could still reside inside the clean() method. But otherwise, constraints are always enforced, there's no need to remember to call full_clean() method. Also, there are usually faster than python validation.

@RadoRado
Copy link
Member

@mkurnikov I actually like this idea. If we can push more validation towards the database, this is less code to write.

I'll add this as an additional idea for doing validations. If you have any good examples to provide, please do so 👍

@RadoRado
Copy link
Member

@mkurnikov Added this - 3c40f63

If you feel there's a need for more explaining & examples, feel free to open a PR.

Until then, I'll close this issue 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants