Adding a hierarchy to a model
You can use an m2o field to represent hierarchies, where each record has a parent record and many child records in the same model. However, Odoo also provides improved support for this type of field by using the nested set model (https://en.wikipedia.org/wiki/Nested_set_model). When activated, queries using the child_of operator in their domain filters will run significantly faster.
Staying with the Hostel example, we will build a hierarchical category tree that can be used to categorize hostels.
Getting ready
We will continue using the my_hostel add-on module from the previous recipe.
How to do it...
We will add a new Python file, models/hostel_categ.py, for the category tree, as follows:
- To load the new Python code file, add the following line to
models/__init__.py:from . import hostel_categ
- To create the
Hostel Categorymodel with the parent and child relationships, create themodels/hostel_categ.pyfile with the following...