For row in tables: # all the tables if row.field_name == 'last_name': # only tables with this field name query = row.organizationID == db.Organization.id #how to reference other fields and data in the located table?query = ((tables.field_name == 'last_name') & (tables.field_name == 'organizationID') & (tables.organizationID == db.Organization.id)) #not sure how to reference data in table that has field_name of "organizationID"
for tablename in db.tables:
table = db[tablename]
if 'last_name' in table and 'organizationID' in table:
rows = db(table.some_field == some_value).select()
[do something with rows]
query = ((db.tables.field == 'organizationID') & (db.tables.field == 'last_name') & (db.tables.table_name.organizationID == 'California')) # so search is looking for mixed data types, one is field name, another is that field name with a specific value
Are you saying you have a "tables" table in your db that stores all the table and field names of the other tables in your db, and you need to know how to query it to get particular information, or are you looking for a way to loop over all the tables you have defined and identify those that include particular fields? Once you have identified the tables of interest, it is not clear what you are then looking to do. Maybe you want something like this:
for tablename in db.tables:
table = db[table]
if 'last_name' in table and 'organizationID' in table:
rows = db(table.some_field == some_value).select()
[do something with rows]
If you need to get a list of field names in a table, you can get that via table.fields.
Anthony
On Wednesday, October 28, 2015 at 12:39:05 AM UTC-4, Alex Glaros wrote:is it possible to do something like this?For row in tables: # all the tablesif row.field_name == 'last_name': # only tables with this field namequery = row.organizationID == db.Organization.id #how to reference other fields and data in the located table?orquery = ((tables.field_name == 'last_name') & (tables.field_name == 'organizationID') & (tables.organizationID == db.Organization.id)) #not sure how to reference data in table that has field_name of "organizationID"
thanks,Alex Glaros
I want to discover the field names in db.py (I do not have them listed in an already-existing table)can you help with syntax for a query?query = ((db.tables.field == 'organizationID') & (db.tables.field == 'last_name') & (db.tables.table_name.organizationID == 'California')) # so search is looking for mixed data types, one is field name, another is that field name with a specific value
for tablename in db.tables:
table = db[tablename]
if 'organizationID' in table.fields and "last_name" in table.fields:
query=table.organizationID == 'California'
The resulting query in grid would look like below (without the numbers in parens):
(1) table_name (2) field_name (3) data_value
for tablename in db.tables:
table = db[table]
should this be table = db[tablename] ?
Anthony