Defining the Model representation and order
Models have structural attributes defining their behavior. These are prefixed with an underscore and the most important is _name
, which defines the internal global identifier for the Model.
There are two other attributes we can use. One to set the field used as a representation, or title, for the records, and another one to set the order they are presented in.
Getting ready
This recipe assumes that you have an instance ready with my_module
, as described in Chapter 3, Creating Odoo Modules.
How to do it…
The my_module
instance should already contain a Python file called models/library_book.py
, which defines a basic model. We will edit it to add a new class-level attribute after _name
:
To add a human-friendly title to the model, add the following:
_description = 'Library Book'
To have records sorted first by default from newer to older and then by title, add the following:
_order = 'date_release desc, name'
To use the
short_name
field as the record...