How to change displayed value for relational field in Odoo
If you want to change the displayed value for a relational field in Odoo, the simplest way to do that is to define the “_rec_name” model’s attribute with the name of the field that you want to show.
For example, if you want to add new field “description” in the hr.employee.category model and you want that field to be shown as value for this model the code should look like:
class Employee(models.Model):
_inherit = 'hr.employee.category'
_rec_name = 'description'
description = fields.Char()
Now when you try to search for a new employee tag in the hr.employee view it will search by and display the description of the hr.employee.category model.
简而言之,简单的改变关系字段的显示,只需要将对应关系字段的model中_rec_name修改成需要显示的字段即可,这样之后的字段显示就是该字段的值。
From:http://www.odooninja.com/change-displayed-value-relational-field-odoo/
- 2019年12月07日11:01:20 更新
1. 默认显示name字段
2. 如果定义了_rec_name则显示对应的字段值
3. 可以重写name_get方法,通过传入的context来个性化显示字段内容