如何在 odoo 8 的列表视图中显示 man2many 字段?
How to display man2many fields in list view in odoo 8?
我尝试了两种在列表视图中显示 many2many 字段的方法,但 none 有效:
1) <field name="test_ids"/>
--> 它只显示记录数。(即(3 条记录))
2) <field name="test_ids" widget="many2many_tags"/>
--> 显示记录的id。 (即 2、3、4)
如何实现?
试试这个。
<field name="test_ids" widget="many2many_tags"/>
通常,
<field name="test_ids" widget="many2many_tags"/>
必须工作。
m2m 列显示 id 的原因是您的联合模型不包含 name 字段或 _rec_name 模型中的声明。
好像您没有相关型号的记录名称。您有两个选择:
- 在相关模型中添加字段名称。
- 在相关模型上定义 _rec_name 以指向包含您要显示的名称的正确字段。
要在列表视图中显示 many2many 字段,您必须使用 many2many_tags
现在它向您显示 ID 列表,因为 Odoo 不知道如何表示
关系字段中的记录。
如何告诉Odoo他如何表示记录有两种方式:
1- 如果您的记录可以由字段的值表示,则使用 rec_name
很简单
例如国家,国家名称足以区分记录
class YourClass..
_name = 'your_model_name'
_rec_name = 'field_name' # here put the name of the field
2-第二个是当一个字段不能代表记录时使用name_get
class YourClass..
_name = 'your_model_name'
.....
.....
# implement this method in you model class
@api.multi
def name_get(self):
""" change representation of the record by concatinating two field"""
result = []
for record in self:
result.append((record.id, _("%s %s") % (
record.some_field, record.some_other_field)))
return result
我尝试了两种在列表视图中显示 many2many 字段的方法,但 none 有效:
1) <field name="test_ids"/>
--> 它只显示记录数。(即(3 条记录))
2) <field name="test_ids" widget="many2many_tags"/>
--> 显示记录的id。 (即 2、3、4)
如何实现?
试试这个。
<field name="test_ids" widget="many2many_tags"/>
通常,
<field name="test_ids" widget="many2many_tags"/>
必须工作。
m2m 列显示 id 的原因是您的联合模型不包含 name 字段或 _rec_name 模型中的声明。
好像您没有相关型号的记录名称。您有两个选择:
- 在相关模型中添加字段名称。
- 在相关模型上定义 _rec_name 以指向包含您要显示的名称的正确字段。
要在列表视图中显示 many2many 字段,您必须使用 many2many_tags
现在它向您显示 ID 列表,因为 Odoo 不知道如何表示 关系字段中的记录。
如何告诉Odoo他如何表示记录有两种方式:
1- 如果您的记录可以由字段的值表示,则使用 rec_name
很简单
例如国家,国家名称足以区分记录
class YourClass..
_name = 'your_model_name'
_rec_name = 'field_name' # here put the name of the field
2-第二个是当一个字段不能代表记录时使用name_get
class YourClass..
_name = 'your_model_name'
.....
.....
# implement this method in you model class
@api.multi
def name_get(self):
""" change representation of the record by concatinating two field"""
result = []
for record in self:
result.append((record.id, _("%s %s") % (
record.some_field, record.some_other_field)))
return result