-1
我的场景是我有一个类deg.form
。在这个类中有两个many2one
字段分别命名为products
和category
。我正在尝试创建many2one
这两个字段与product.product
类中存在的其他两个字段的关系。 product.product
中的字段是name
和asset_type
。我创建字段作为关系:如何创建2个many2one字段?
class deg_form(osv.osv):
_name = "deg.form"
_inherit="product.product"
_columns = {
'categ1':fields.many2one('product.category','Category'),
'products':fields.many2one('product.product','Parent'),
'category':fields.many2one('product.product',string='Product'),
'product':fields.related('category','asset_type', type="many2one", relation ="product.product")
}
在这样做,我得到一个错误:
Value Error: No such external ID currently defined in the system: product.product
我猜有可能是我在这里失踪的任何参数,或者其继承问题。 Plz指导我解决这个问题或指出我错在哪里。由于
问候
抱歉,但我不明白你的问题很好。上面有2个many2one字段作为model.product的关系。如果你想与product.product的领域(例如类别或类型)的关系,你必须使用相关领域,而不是many2one或其他。 – CZoellner
我们不能使用many2one而不是相关的,因为我尝试了相关的属性,但没有为我工作。 –
相关你需要一个many2one字段,然后你可以使用相关的领域为many2one关系。例如:'product_id':fields.many2one('product.product',string =“Product”),'product_type':fields.related('product_id','type',type =“selection”,string =“产品类型“) – CZoellner