Extending models
To extend an existing model, we use a Python class with an _inherit
attribute, identifying the model to be extended. The new class inherits all the features of the parent Odoo model, and we only need to declare the modifications we want to introduce. These modifications will also be available everywhere else this model is used. We can think about this type of inheritance as getting a reference for the existing model and making in-place changes to it.
Adding fields to a model
We will extend the todo.task
model to add some fields to it. As an example, we will now add the effort_estimate
field, to be used for the amount of time expected to be spent on the task.
We will do this in a models/todo_task_model.py
file, so we should also import it in the todo_stage/models/__init__.py
file to have this content:
from . import todo_task_tag_model
from . import todo_task_stage_model
from . import todo_task_model
Now, create the todo_stage/models/todo_task_model.py
file, extending the original...