How it works...

When a model class is defined with the _inherit attribute, it adds modifications to the inherited model, rather than replacing it.

This means that fields defined in the inheriting class are added or changed on the parent model. At the database layer, the ORM is adding fields on the same database table.

Fields are also incrementally modified. This means that if the field already exists in the superclass, only the attributes declared in the inherited class are modified; the other ones are kept as they are in the parent class.

Methods defined in the inheriting class replace methods in the parent class. If you don't invoke parent method with the super call, in that case the parent's version of the method will not be executed and we will lose the features. So, whenever you add a new logic by inheriting existing methods, you should include a statement with super to call its version in the parent class. This is discussed in more detail in Chapter 6, Basic Server-Side Development.

This recipe will add new fields to the existing model. If you also want to add these new fields to existing views (the user interface), refer to the Changing existing views – view inheritance recipe in Chapter 10, Backend Views.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset