Many-to-one relationships

The Many2one relationship accepts two positional arguments: the related model (corresponding to the comodel keyword argument) and the title string. It creates a field in the database table with a foreign key to the related table.

Some additional named arguments are also available to use with this type of field:

  • ondelete defines what happens when the related record is deleted. Its default is set null, meaning that an empty value is set when the related record is deleted. Other possible values are restricted, raising an error preventing the deletion, and cascade, which also deletes this record.
  • context is a dictionary of data, meaningful for the web client views, to carry information when navigating through the relationship, ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.