SOLVED:
Credit to stucork:
Figure out the Table a row is associated with:
tables = [app_tables.Table1, app_tables.Table2]
for table in tables:
if table.has_row(row_object)
break
else: # no break
raise Exception('row does not exist in any known table')
Credit to campopiano:
Figure out the columns in a table:
columns = app_tables.MyTable.list_columns()
# This returns a dict of columns and field types
list_columns() I’ve never used it but I believe you pass the table object in as an argument. You could extrapolate that to also find the columns associated with a table (your 1st question).
If the row object is a dict, I think you can go:
value = my_dict_row.get('some_key', <someDefaultValue>)
Great find on the list_columns method of app_table objecsts! That checks that one off the list…
Row objects are ‘dict-like’ but they don’t have a get method (I definitely think they should)! Conversion of row objects to dictionaries causes other problems.
As an alternative to 1 - tables have a has_row method.
tables = [app_tables.Table1, app_tables.Table2]
for table in tables:
if table.has_row(row_object)
break
else: # no break
raise Exception('row does not exist in any known table')
Noted on the request to add useful dict-like methods to row objects.
Great, thanks stucork! I will take this as a solution since it’s significantly less gross… but suggest that it would be helpful if we could get the table directly from the row object somehow!