填充Many2many字段(odoo 8) [英] Filling Many2many field (odoo 8)
问题描述
我所做的事情:
我有一个带有
myfield = fields.Many2one('res.partner', string="Graduate", domain=[('is_graduated', '=', True)])
那我还有另外一个课
_inherit = 'res.partner'
is_graduated = fields.Boolean("Graduated before?", default=False)
graduations = fields.Many2many('my_module.courses', string="Graduation courses")
我得到的:
myfield
工作正常,但graduations
字段为空.如果您编辑user 1
配置文件,则可以使用Add item
将条目添加到graduation
字段中,但是我需要自动填充它.
The myfield
works good, but the graduations
field is empty. If you edit user 1
profile you can add entries to graduation
field using Add item
, but I need it to be filled automaticaly.
我期望的是
我希望打开user 1
配置文件时,在graduations
字段中设置为user 1
的每个记录都将在字段graduations
中可见.当我创建记录并将myfield
值设置为user 1
时,该记录必须在graduations
字段的user 1
配置文件中可见.如何实现?
I expect that every record where myfield
is set to lets say user 1
, will be visible in field graduations
when you open user 1
profile. When I create record and set myfield
value to lets say user 1
, that record must to be visible in user 1
profile in the field graduations
. How to achieve that?
推荐答案
user_rel_ids =字段.Many2many(comodel_name ='course', 关系='user_course_rel', column1 ='user_id', column2 ='course_id')
user_rel_ids = fields.Many2many(comodel_name='course', relation='user_course_rel', column1='user_id', column2='course_id')
或
user_rel_id = fields.Many2many('course')
用于填充数据(用于添加新关系)
For Filling Data (for add new relation)
user_rel_id = [(4,course_id)]
根据 http://odoo4u.blogspot.com/2014/10 /orm-methods.html ,它表示: 选项的完整列表在该类的文档中. 这同样适用于一个人
According to http://odoo4u.blogspot.com/2014/10/orm-methods.html, It says: A full list of options is in the documentation for the class. This same thing will apply for one2many
对于 many2many 和 one2many 字段,元组列表为 预期的.这是被接受的元组列表,其中 相应的语义:
For a many2many and one2many field, a list of tuples is expected. Here is the list of the tuple that is accepted, with the corresponding semantics:
(0, 0, { values })
链接到需要保存的新记录
用给定的值字典创建
(0, 0, { values })
link to a new record that needs to be
created with the given values dictionary
(1, ID, { values })
更新 ID = ID的链接记录(写
值)
(1, ID, { values })
update the linked record with id = ID (write
values on it)
(2, ID)
删除并删除链接ID为ID(通话)的记录
取消ID链接,这将完全删除该对象,并链接到
也是如此)
(2, ID)
remove and delete the linked record with id = ID (calls
unlink on ID, that will delete the object completely, and the link to
it as well)
(3, ID)
剪切到id = ID的链接记录的链接(删除
两个对象之间的关系,但不会删除目标
对象本身)
(3, ID)
cut the link to the linked record with id = ID (delete the
relationship between the two objects but does not delete the target
object itself)
(4, ID)
链接到ID = ID的现有记录(添加一个
关系)
(4, ID)
link to existing record with id = ID (adds a
relationship)
(5)
取消所有链接(例如对所有链接的记录使用(3,ID))
(5)
unlink all (like using (3, ID) for all linked records)
(6, 0, [IDs])
替换列表的链接ID(例如使用(5)
然后(4,ID)代表ID列表中的每个ID)
(6, 0, [IDs])
replace the list of linked IDs (like using (5)
then (4,ID) for each ID in the list of IDs)
这篇关于填充Many2many字段(odoo 8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!