Typically I send table rows as a list of dicts and include both the id and the row itself
def get_row_as_dict(row):
row_as_dict = dict(row)
row_as_dict['row'] = row
row_as_dict['id'] = row.get_id()
rows_as_dicts = []
for row in app_tables.my_table.search():
row_as_dict = get_row_as_dict(row)
rows_as_dicts.append(row_as_dict)
return rows_as_dicts
I adapt this if I have linked rows that I also need to unpack.
I do it this way because I like the syntax for updating a table row
@anvil.server.callable
def update_row(row_as_dict):
row = row_as_dict["row"]
row.update(**{k:row_as_dict[k] for k, _ in row})
I also like to have the id
just in case I need it. but also because I use the Tabulator dependency which works best with a unique identifier for row objects and the id
seems the most sensible.
Getting a table_row
by id
is a quick lookup for anvil on the server so working with the id
alone to get the table row
won’t be a performance issue.
NB: you do need to know which table
the row
came from in order to look it up