1. In this Example i need to take the input string from table_1.field_1 and get_or_create a record in table_2 with table_1.field_1 value in table_2.field_1 and insert the table_2.field_2 refernce in table_1.field_2:
def get_or_create(table, fields): logic=reduce(lambda a,b:a&b,[table[k]==fields[k] for k in fields]) record = db_bluetooth(logic).select(table['id'],limitby=(0,1)).first() if record: return record.id else: return table.insert(**fields).id def get_reference_3(): value=request.vars.field_1 if value: get_table2_id=get_or_create(db.table2, {'field_1': value,}) query=(db.table_2.id==get_table_2_id) record = db(query).select(db.table_2.field_2) return record else: pass db.define_table('table_1', Field('field_1','string', default=get_reference_3), Field('field_2', db.table_3) ) db.table1.field_2.requires=IS_IN_DB(db,'table_3.id','table_3.field1') db.define_table('table_2', Field('field_1','string'), Field('field_2', db.table_3) ) db.table2.field_2.requires=IS_IN_DB(db,'table_3.id','table_3.field1') db.define_table('table_3', Field('field_1','string') ) ##################################################################### 2. and i need to know how to do this: lets say we have two IS_IN_DB dropdown-lists in a table, like this drop-down_1 drop-down_2 major_item_1 minor_1_major1 major_item_2 minor_2_major1 major_item_3 minor_3_major2 minor_4_major3 when the user selects major_item_1, only minor 1 and 2 should be available in drop_down_2 Thank you.