We have seen the basic in place extension of models, which is also the most frequent use of inheritance. But inheritance using the _inherit
attribute has more powerful capabilities, such as mixin classes.
We also have available the delegation inheritance method, using the _inherits
attribute. It allows for a model to contain other models in a transparent way for the observer, while behind the scenes each model is handling its own data.
Let's explore these possibilities in more detail.
The method we used before to extend a model used just the _inherit
attribute. We defined a class inheriting the todo.task
model, and added some features to it. The class attribute _name
was not explicitly set; implicitly it was todo.task
also.
But using the _name
attribute allows us to create mixin classes, by setting it to the model we want to extend. Here is an example:
from openerp import models class TodoTask(models.Model...