我有两个模型employee
。 employee
包含emp_name
和emp_pnum
列。
我在employee
和res_users
之间有一个Many2One关系,如代码所示。
class Employee(models.Model):
_name = "employee"
emp_name = fields.Char(string='Employee name')
emp_pnum = fields.Char(string='Phone number')
user_id = fields.Many2one('res.users', string='user id', default=lambda self: self.env.uid, required = True)
在表单视图中,我希望在表单视图中的res.users
模型中显示employee
模型字段旁边的字段。
<record model="ir.ui.view" id="employee_tree">
<field name="name">employee.tree</field>
<field name="model">employee</field>
<field name="priority" eval="8" />
<field name="arch" type="xml">
<tree string="Employee">
<field name="user_id" readonly="1"/>
<field name="emp_name"/>
<field name="emp_pnum"/>
//// I want to add the field values from the res.users table
//// through the Many2One relationship here
</tree>
</field>
</record>
答案 0 :(得分:1)
请在您的代码中尝试此逻辑:
模特A:
model_A1 = fields.Char()
model_desc = fields.Char()
模特B:
model_A1_child = fields.Many2one('modelA')
model_A1_desc = fields.Char(related='model_A1_child.model_desc')