Odoo 中的 OneToMany 字段 link 两个模型的正确方法

OneToMany field in Odoo proper way to link two models

    raise UserError(_("No inverse field %r found for %r") % (self.inverse_name, self.comodel_name))
odoo.exceptions.UserError: ("No inverse field None found for 'res.sector'", '' )

我正在尝试创建一个新模型,但在将其链接到另一个模型时遇到问题。

您可能声明了一个 One2many 字段,如下所示:

field_name = fields.One2many('res.sector')

您需要指定反向名称(必填),即在 res.sector 中声明的 Many2one 字段的名称,它引用您声明 One2many 字段的模型。

如上所述,您需要在关系上指定一个反向名称。

例如:(workcenter_id)是逆域

equipment_ids = fields.One2many('maintenance.equipment', 'workcenter_id')