【问题标题】:How to change value of a selection using Python on Tryton如何在 Tryton 上使用 Python 更改选择的值
【发布时间】:2014-08-27 21:48:21
【问题描述】:

有没有办法使用 Python 更改选择字段值,但我没有找到任何要使用的文档。 state 字段是描述治疗状态的字段

我想做类似的事情:

state=fields.Selection([
        ('stopped', 'Stopped'),
        ('wait', 'Wait'),
        ('finished', 'finished'),
        ], 'State', readonly=True)

def changeselectionvalue(self,state)
    self.state=state #something to do this

请帮助我,我是 Tryton 的新用户

【问题讨论】:

  • 您对哪个部分有问题?将操作绑定到您的方法,还是实际更改字段的值?
  • 更改字段值

标签: python tryton


【解决方案1】:

只需使用 write API:

records = Model.search([]) #Get all the records you wan to write. 
Model.write(records, {'state': 'new_state'})

或者 ActiveRecord 模式:

self.state = 'new_state'
self.save()

'new state' 必须是选择的内部值之一。

当您必须更新多个记录时,建议使用第一个。

如果您是 Workflow 类的模型子类,建议使用 @Workflow.transition(new_state) 装饰器来更改记录的状态,因为它只更新转换有效的记录。

【讨论】:

    猜你喜欢
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 2016-09-28
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    相关资源
    最近更新 更多