【问题标题】:how to edit records in the database using Tryton code如何使用 Tryton 代码编辑数据库中的记录
【发布时间】:2014-10-12 13:07:28
【问题描述】:

我想使用 Tryton 代码编辑(添加或删除)数据库中的记录。

我应该使用哪个函数或方法来修改 Tryton 中的记录?

例子:

status=fields.Char("status")

如何删除字段status 的所有记录并添加一个值为status1 的新记录?

【问题讨论】:

    标签: python database python-2.7 tryton


    【解决方案1】:

    你只需要使用 ORM 方法来搜索你想要的值然后删除它们。比如:

    pool = Pool()
    Model = pool.get('your.model.name')
    
    records = Model.search([('status', '=', 'search_value')])
    Model.delete(records)
    

    要创建新的,只需使用带有字典列表的 create 方法。每个字典键必须是字段的名称,它们的值是您要设置的值。比如:

    values = [{'state': 'one'}, {'state': 'two'}]
    Model.create(values)
    

    将创建两条记录,一条状态 == 'one',另一条状态 == 'two'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-11
      • 2021-08-06
      • 2012-06-13
      • 1970-01-01
      相关资源
      最近更新 更多