If we obtain a recordset of model instances (through search() or browse()), what kinds of operations are available? Can recordsets be added (set + set)? Can they be appended to (setA.append(record))?
Does the recordset behave like some well known Pythonic structure (like list)? If not, is there some kind of reference that lists what operations are and aren't available?
Other recordset operations:
1. sorted(): To sort a recordset
# sort records by name
recset.sorted(key=lambda r: r.name)
2. filtered(): To filter a recordset:
# only keep records whose company is the current user's
records.filtered(lambda r: r.company_id == user.company_id)
# only keep records whose partner is a company
3. mapped(): To map a recordset by applying the provided function to each record in the recordset and returns a recordset if the results are recordsets.
recordset.mapped(lambda record: record.amount + record.tax_amount)
# returns a list of name
# returns a recordset of partners
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 9/3/14, 4:31 AM|
|Seen: 2514 times|
|Last updated: 10/30/15, 3:35 AM|