如何限制多对多字段修改主模型?

2024-04-28 19:51:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我在产品表单上添加了许多字段,其中显示了另一个模型中的一些产品详细信息 我需要在产品表单中编辑该字段,而不修改详细信息模型

代码如下:

class autopart(models.Model):
_inherit = 'product.template'

related = fields.Many2many(comodel_name="relate",relation='car', string="", )


class relate(models.Model):
_name = 'relate'
_rec_name = 'code'

code = fields.Char(string="product Code", required=False)
car = fields.Many2one(comodel_name="cars", string="car", required=True, ondelete='restrict', )
model = fields.Many2many(comodel_name="models", string="",domain="[('car','=', car )]" )
start = fields.Char(string="", required=False, )
end = fields.Char(string="", required=False, )
rang = fields.One2many(comodel_name="yearrange", inverse_name="product_id", store=True, string="Years")
ignore = fields.Char(string="Ignore", required=False, )
pro = fields.Integer(string="", required=False, )

Tags: name模型false表单fieldsstring产品models