Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在tryton中填充选择字段_Python_Tryton - Fatal编程技术网

Python 如何在tryton中填充选择字段

Python 如何在tryton中填充选择字段,python,tryton,Python,Tryton,我有两个模块,第一个是employee,第二个是pointage。 我正在尝试添加一个允许我选择点年龄的选择字段 为此,我们必须创建一个元组列表pointagedef=[('','')] 现在我们已经填写了,但问题是我找不到任何文档来理解如何填写 pointage= fields.Selection(pointagedef, 'grh.pointage') 我正在尝试做一些类似的事情: for pointage in pointages: pointagedef.append((

我有两个模块,第一个是
employee
,第二个是
pointage
。 我正在尝试添加一个允许我选择
点年龄的选择字段

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

pointage= fields.Selection(pointagedef, 'grh.pointage')   
我正在尝试做一些类似的事情:

for pointage in pointages:
    pointagedef.append((pointage, pointage))
colors = fields.Selection([
   ('red', 'Red'),
   ('green', 'Green'),
   ('blue', 'Blue'),
], 'Colors')

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

for pointage in pointages:
    pointagedef.append((pointage, pointage))
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

另外,如果要访问单个表,可以使用manyOne字段,在视图定义中添加widget=“selection”,这样客户端将呈现一个选择小部件而不是默认的小部件,并将表的所有记录预加载到选择中

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

for pointage in pointages:
    pointagedef.append((pointage, pointage))
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

另外,如果要访问单个表,可以使用manyOne字段,在视图定义中添加widget=“selection”,这样客户端将呈现一个选择小部件而不是默认的小部件,并将表的所有记录预加载到选择中

不,这不是我要找的,我要从数据库中填充选择字段,所以在get_colors方法中,只需访问数据库。我编辑了回复以显示一个示例。这似乎是我要找的。感谢您的支持。我将尝试不这不是我要找的。我要从数据库中填充选择字段。因此,在get_colors方法中,只需访问数据库即可。我编辑了回复以显示一个示例。这似乎是我想要的。谢谢你的支持,我会尝试的