Adding constraints validations to a model
We want to make sure that our models do not have invalid or inconsistent data. Odoo has two kinds of constraints to do this:
Database-level constraints: These are the constraints that PostgreSQL supports. The most common ones are theUNIQUEconstraints, which prevent duplicate values. We can also useCHECKandEXCLUDEconstraints for other conditions. These constraints are fast and reliable, but they are limited by what PostgreSQL can do.Server-level constraints: These are the constraints that we write in Python code. We can use these constraints when the database-level ones are not enough for our needs. These constraints are more flexible and powerful, but they are slower and more complex.
Getting ready
We will continue using the my_hostel add-on module from the previous recipe. We will use the hostel room model and add some constraints to it. We will use the hostel room model from Chapter 3, Creating Odoo Add-On Modules...