关联字段
在关联字段中,我们可让用户操作做一些额外控制。默认用户从这些字段中创建新记(也称作“快速创建”)并打开关联记录表单。可通过options字段属性来关闭:
1
| options="{'no_open': True, 'no_create': True, 'no_create_edit': True}"
|
context
和domain
也是字段属性并对于关联字段特别有用。
context
可定义关联字记录默认值,domain
可限制可选记录。常见的示例为让一个字段依赖其它字段值来产生选择项。domain
可在模型中直接定义,但也可在视图中进行覆盖。
- 在to-many字段中,我们还可使用
mode
属性来更改用于显示记录的视图类型。默认为tree
,但还有其它选项:form
, kanban
或graph
。
- 关联字段可定义行内指定视图来使用。这些视图在元素中的嵌套视图定义中声明。
- 例如,在
line_ids
借阅中,我们可以为这些线路定义特定的列表和表单视图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <notebook> <page string="Borrowed Books" name="page_lines"> <field name="line_ids"> <tree editable="buttom"> <field name="book_id"/> <field name="author" widget="many2many_tags" options="{'color_field': 'color'}"/> <field name="publish"/> </tree>
</field> </page> </notebook>
|
线路列表将带有给定的<tree>
定义。当我们与线路交互时,弹出一个表单对话框,在<form>
定义中包含该结构。
如果想要在列表视图的表单弹出窗口中直接编辑one-to-many路线,应使用
1 2 3
| <tree editable="top"> 或 <tree editable="bottom">
|
