官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 苍山县| 鄂州市| 三亚市| 株洲县| 中西区| 崇州市| 桂平市| 焦作市| 公主岭市| 建平县| 泽库县| 嘉鱼县| 胶州市| 营口市| 仁布县| 双柏县| 崇阳县| 和静县| 临夏市| 德保县| 桦川县| 军事| 龙州县| 阳城县| 田林县| 张掖市| 东至县| 和顺县| 兴国县| 富顺县| 富宁县| 富平县| 安国市| 房产| 马鞍山市| 苍山县| 新郑市| 绥棱县| 黎城县| 中阳县| 河津市|