
Odoo 15 Development Essentials
By :

Models are the basic components for building applications and provide the data structures and storage to be used. Next, we will create the model for our to-do list app with three fields:
Is Done?
flagModel names should use the singular form, so the new model should be named To-do Item. The model technical name must be a valid database object identifier, so we should use letters and underscores and avoid other symbols. Since the models created through the Technical menu must have an x_
prefix, the technical name for the new model will be x_todo_item
.
Model definitions are accessed in the Settings app in the Technical | Database Structure | Models menu.
To create a new model, click the Create button on the Models list:
To-do Item
in the Model Description field and x_todo_item
for the Model field.x_name
field. This is a title that represents the record in lists or when it is referenced in other records. It can be used for the To-do Item title, so edit it to change the Field Label column accordingly.Is Done?
field. This should be straightforward. On the Fields list, click Add a line at the bottom of the list to open the new field form, and then, enter these values:x_is_done
Is Done?
Then, click the Save & Close button and click Save on the model form.
Figure 1.12 – The Create Fields form
res.partner
) model, but it is also a multiple-value selection field.Fortunately, Odoo supports many-to-many relations. This is the case here since a to-do item can be related to many contacts, and each contact can be related to many to-do items.
To add the Work Team field on the Fields list, click again on the form Edit button, then click Add a line to open the new field form. Then, enter these values:
x_work_team_ids
Work Team
many2many
res.partner
[('x_is_work_team', '=', True)]
Many-to-many fields have a few specific base properties: Relation Table, Column 1, and Column 2. These are automatically filled out for you, and the defaults work for most cases. These properties are discussed in more detail in Chapter 6, Models – Structuring the Application Data.
The Domain
attribute is optional and defines a filter for the records to be presented. We are using it to limit the selectable contacts to the ones that have the Is Work Team?
flag checked on them. Otherwise, all contacts would be available for selection.
The domain expression to use follows an Odoo-specific syntax – it is a list of triplets, where each triplet is a filter condition, indicating the field name to filter, the filter operator to use, and the value to filter against. A detailed explanation of domain expressions is given in Chapter 7, Recordsets – Working with Model Data.
Tip
Odoo has an interactive domain filter wizard that can be used as a helper to generate domain expressions. To use it, select the Settings | Technical | User Interface | User-defined Filters menu option. Once a target model is selected in the form, the Domain field will display an + Add filter button to add filter conditions. When doing so, the textbox below it will dynamically show the corresponding domain expression code.
Figure 1.13 – The database structure for the To-do Item model
We now have the underlying model for the to-do list app, but it is still not accessible by users. For that, access security needs to be configured. So, let's look at that in the next section.