首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在文件中添加Many2One数据

如何在文件中添加Many2One数据
EN

Stack Overflow用户
提问于 2019-09-16 13:27:06
回答 1查看 804关注 0票数 0

我有几个相互依赖的模型,它们之间有Many2One和One2Many关系。

我已经设置了所有的视图,但是现在我通过数据文件添加数据来测试所有我发现我不知道如何添加这些记录的东西。

我是否应该在声明记录的同时将关系值保持为空,然后用关系更新记录呢?

此外,关系字段的值应该是什么?数组之类的?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-16 14:59:32

您可以始终使用内置模块的演示和数据文件作为参考。

如您所见,这里 category_ids is is Many2many字段(对one2many字段同样适用)

要理解<field name="category_ids" eval="[(6, 0, [ref('employee_category_2')])]"/>属性的值,请阅读以下内容:

代码语言:javascript
运行
复制
(0, 0,  { values })    link to a new record that needs to be created with the given values dictionary
(1, ID, { values })    update the linked record with id = ID (write *values* on it)
(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)                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)                link to existing record with id = ID (adds a relationship)
(5)                    unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs])          replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

对于它的值中的ref函数(即这个部分ref('employee_category_2') ),它是一个在加载数据文件时计算出来的python函数,它接受相关字段的XML recordID (有时您可能需要使用外部ID --例如,在这种情况下,记录的外部id是hr.employee_category_2)

参考资料: 1 2

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57957897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档