python - 如何在一个多对一字段中连接多个字符字段?

标签 python xml python-2.7 odoo odoo-10

我想将多个字符字段连接到一个多对一字段中,并在其他模块中访问它。我们怎样才能做到这一点?

For example:- I have 5 character fields with different classes in a module and want to concatenate these 5 character fields in a single many2one field. Also I want access this many2one field in another module.

有人可以帮我吗?

最佳答案

使用name_get函数。

例如:

@api.multi
@api.depends('name', 'state')
def name_get(self):
    result = []
    for move in self:
        if move.state == 'draft':
            name = '* ' + str(move.id)
        else:
            name = move.name
        result.append((move.id, name))
    return result

希望对您有帮助。

关于python - 如何在一个多对一字段中连接多个字符字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46989213/

相关文章:

objective-c - 使用 XMLParser 访问正确的 XML 节点

javascript - 如何从 jQuery 中的变量中删除换行符和空格

android - Kotlin 中的 STRING_TOO_LARGE 字符串

java - 滚动时如何修复折叠工具栏中的 View ?

python - 如果没有要爬行的网址,Scrapy 会关闭蜘蛛

python - 如何将此代码从 Python 2.7 转换为 Python 3.5 以修复 ---> AttributeError : '_io.TextIOWrapper' object has no attribute 'next'

multithreading - 从多个线程同时从单个串行端口读取和写入

python - 使用 LFU 设计缓存服务器以降低数据库负载

python - 在单个文件上使用多个 genfromtxt

即使 "Requirement Already satisfied in Pip"也找不到 Python 模块