Odoo | 技巧 | 字段显示-关系字段的显示值自定义

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来个性化显示字段内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

比特本特

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值