如何从tryton的多个字段中检索所选值

2024-10-03 21:35:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须创建一个名为Category的manyOne或Selection字段和一个名为echelon的字段。对于一个类别,我们联想到许多梯队。这就像选择国家的例子,对于这个国家,我们通过关联的细分填充另一个字段。我的代码:


categoryy=fields.Many2One("grh.category","Category")
ech = fields.Many2One("grh.echelon",'echelon', depends=[ 'categoryy'])

@fields.depends('ech', 'categoryy')
def on_change_categoryy(self):
    if (self.ech
            and self.ech.echeloncategory != self.categoryy):
        return {'ech': None}
    return {}

^{pr2}$
from trytond.model import ModelView,ModelSQL,fields
from trytond.pool import Pool

__all__ = ['category']


class category(ModelView,ModelSQL):
    '''category'''
    __name__ = "grh.category"
    category=fields.Char("category")
    echelons=fields.One2Many("grh.echelon","echeloncategory","Category echelons")

我不知道为什么“梯队”场上显示了所有的梯队

请帮帮我


Tags: fromselffieldsreturn国家dependscategorymany2one
1条回答
网友
1楼 · 发布于 2024-10-03 21:35:24

您应该使用domain子句来限制ech字段上的可用选项。您可以在以下位置找到域的完整引用:

http://doc.tryton.org/3.2/trytond/doc/topics/domain.html?highlight=domain

此外,您必须使用PYSON来获取类别的当前值,因此您将得到如下结果:

from trytond.pyson import Eval
ech = fields.Many2One("grh.echelon",'echelon', 
    domain=[
        ('category', '=', Eval('category', -1)),
    depends=['categoryy'])

您可以在以下网站找到关于PYSON的介绍:

http://doc.tryton.org/3.2/trytond/doc/topics/pyson.html

相关问题 更多 >