Hi, I want to use two tables and one grid. For each person (table 1) there could be some rows in table 2. Table 2 should be edited with a grid. If one person is selected from table 1 the name of the person should only be readable in table 2.
The id of the selected person should be the default person-id in table 2. I have found the following solution, but it seems to be a little bit complicated to use a function pnr for the id of the person. Any ideas how to make it better? In db.py (simplified): pnr = None db.define_table('person', Field('name'), ) db.define_table('cv', # curriculum vitae Field('person', db.person, writable=False, readable=True, default=lambda: pnr(), represent=lambda v,r: db.person[v].name), Field('status',requires = IS_IN_SET(['student','teacher','something else'])), Field('date','date'), ) In default.py: def editcv(): pr = db(db.person.name=='Smith').select() # or something like this... pnr = lambda:pr.first().id return dict(grid=SQLFORM.grid( query=db.cv.person==pnr(), user_signature=False, )) And just some other question: - How to do it with a smartgrid? - How to use the parameters fields, field_id and constraints of a smartgrid? - Are there any examples? Regards, Martin