上QQ阅读APP看书,第一时间看更新
Model attributes
Model classes can use additional attributes that control some of their behaviors. These are the most commonly used attributes:
- _name is the internal identifier for the Odoo model we are creating. Mandatory when creating a new model.
- _description is a user-friendly title for the model's records, shown when the model is viewed in the user interface. Optional but recommended.
- _order sets the default order to use when the model's records are browsed, or shown in a list view. It is a text string to be used as the SQL order by clause, so it can be anything you could use there, although it has smart behavior and supports translatable and many-to-one field names.
For completeness, there are a couple more attributes that can be used in advanced cases:
- _rec_name indicates the field to use as the record description when referenced from related fields, such as a many-to-one relationship. By default, it uses the name field, which is a common field in models. But this attribute allows us to use any other field for that purpose.
- _table is the name of the database table supporting the model. Usually, it is left to be calculated automatically, and is the model name with the dots replaced by underscores. But it's possible to set it to indicate a specific table name.
We can also have the _inherit and _inherits attributes, used to extend modules. We will look closer at them later in this chapter.