【问题标题】:how fill Selection field in tryton如何在tryton中填写选择字段
【发布时间】:2014-08-01 22:17:32
【问题描述】:

我在 tryton 中有 2 个模块,第一个是 employee,第二个是 pointage。 我正在尝试添加一个允许我选择 pointage 的选择字段。

为此,我们必须创建一个元组列表pointagedef = [('', '')] 现在我们已经填写了它,但问题是我找不到任何文档来了解如何做到这一点

pointage= fields.Selection(pointagedef, 'grh.pointage')   

我正在尝试做类似的事情:

for pointage in pointages:
    pointagedef.append((pointage, pointage))

【问题讨论】:

    标签: python tryton


    【解决方案1】:

    你只需要声明一个包含两个值元组的列表。比如:

    colors = fields.Selection([
       ('red', 'Red'),
       ('green', 'Green'),
       ('blue', 'Blue'),
    ], 'Colors')
    

    第一个值将是内部值,并将存储在数据库中。第二个值是客户端显示的值,默认情况下是可翻译的。

    你也可以传递一个函数名,它返回两个值元组的列表。例如:

    colors = fields.Selection('get_colors', 'Colors')
    
    @classmethod
    def get_colors(cls):
       #You can access the pool here. 
       User = Pool.get('res.user')
       users = User.search([])
       ret = []
       for user in users:
          if user.email:
             ret.append(user.email, user.name)
       return ret
    

    另外,如果你想访问单个表,你可以使用Many2One字段,在视图定义中添加widget="selection",这样客户端会渲染一个选择widget而不是默认的,并预加载所有记录表到选择。

    【讨论】:

    • 不,这不是我想要的,我正在寻找从数据库中填写选择字段
    • 所以在get_colors方法中,只要访问数据库即可。我编辑了响应以显示一个示例。
    • 看来我在找什么谢谢你的支持我会试试的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2017-03-28
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    相关资源
    最近更新 更多