odoo many2one,在视图显示什么?
作者:互联网
当我们定义了many2one的时候,是希望在另一张表里面选择我们制定好的可填范围。
那么选择的时候显示什么呢?
默认是显示name这个名字
具体可以看 odoo/models.py BaseModel 下有个函数
def name_get(self): """ name_get() -> [(id, name), ...] Returns a textual representation for the records in ``self``. By default this is the value of the ``display_name`` field. :return: list of pairs ``(id, text_repr)`` for each records :rtype: list(tuple) """ result = [] name = self._rec_name if name in self._fields: convert = self._fields[name].convert_to_display_name for record in self: result.append((record.id, convert(record[name], record))) else: for record in self: result.append((record.id, "%s,%s" % (record._name, record.id))) return result
如果你没定义name这个名字,就会显示的乱七八糟,如果你像显示的更复杂一些,也要复写这个方法
下面是返回class_name
当然你也可以继续改写
class labor_personnel_personnel_order_class(models.Model): _name = "labor_personnel.personnel_order_class" class_name = fields.Char() def name_get(self): # 重写函数,更改many2one显示值名字和指定返回ID result = [] for record in self: name = record.class_name # 实现修改显示值名字 result.append((record.id, name)) return resultView Code
标签:name,self,many2one,视图,class,record,result,odoo,id 来源: https://www.cnblogs.com/jackadam/p/16465832.html