Conteúdo do Curso
Django ORM Ninja: Advanced Techniques for Developers
Django ORM Ninja: Advanced Techniques for Developers
Constrains
This is an additional option within the Meta class, utilized for establishing certain constraints on the model. Implementing the unique=True
option on a field effectively acts as a constraint.
UniqueConstraint
Ensures that the combination of specified field values is unique across the database table.
In this example, the UniqueConstraint
ensures that no two books in the same genre have the same title.
CheckConstraint
Ensures that certain conditions hold true for the data in the database.
Suppose you want to ensure that the author's age is always greater than 18.
Obrigado pelo seu feedback!