1

I want to edit (add or delete) records in the database using Tryton code.

Which function or method should I use to modify records in Tryton?

Example:

status=fields.Char("status")

How can I delete all records of field status and add a new one which has the value status1?

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
sarra
  • 21
  • 3

1 Answers1

0

You just need to use the ORM methods in order to search for the values you want and then delete them. So for example:

pool = Pool()
Model = pool.get('your.model.name')

records = Model.search([('status', '=', 'search_value')])
Model.delete(records)

In order to create new ones just use a the create method with a list of dictionaries. Each dictionary key must be the name of the field, and their value the value you want yo set. So for example:

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

Will create two records, one with state == 'one' and the other with state == 'two'

pokoli
  • 1,045
  • 7
  • 15