March 2018
Beginner to intermediate
336 pages
8h 22m
English
An inverse of a Many2one can be added to the other end of the relationship. This has no impact on the actual database structure, but allows us to easily browse from the one side of the many related records. A typical use case is the relationship between a document header and its lines.
In our example, a One2many inverse relationship on stages allows us to easily list all the tasks in that stage. The code to add this inverse relationship to stages is as follows:
class Stage(models.Model):
_name = 'todo.task.stage'
# Stage class relationship with Tasks
task_ids = fields.One2many(
'todo.task', # related model
'stage_id', # field for "this" on related model
'Tasks in this stage')
One2many accepts three positional ...
Read now
Unlock full access