Foreign keys validation inside models #3943
-
I have the following tables:
following, the description of the relationships:
The problem with this setup is the following: In Django, I would use model validation: https://docs.djangoproject.com/en/4.1/ref/models/instances/#django.db.models.Model.clean Is it possible to have the same type of validator at the model level? Maybe do the foreign keys check in the beforeCreate hook and, if something goes wrong, throw an Exception inside the hook? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yeah, you can use |
Beta Was this translation helpful? Give feedback.
Yeah, you can use
beforeCreate
orbeforeSave
hooks for the same