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:

  1. To add a human-friendly ...

Get Odoo Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.