I've read the section about "one form for multiple tables" and
following the example created my function that updates four tables:
def register():
form=SQLFORM.factory(db.person, db.affiliation, db.address, db.card)
if form.accepts(request.vars):
id = db.person.insert(**db.person._filter_fields(form.vars))
form.vars.person=id
id = db.affiliation.insert(**db.affiliation._filter_fields(form.vars))
id = db.address.insert(**db.address._filter_fields(form.vars))
id = db.card.insert(**db.card._filter_fields(form.vars))
return dict(form=form)
That works fine. Now, following the book convention, I tried to display
the same record set but it produces an error:
def display():
record = db.person(request.args(0))
form=SQLFORM.factory(db.person, db.affiliation, db.address, db.card, record)
if form.accepts(request.vars, session):
record.update_record(**dict(form.vars))
return dict(form=form)
Traceback (most recent call last):
File "/home/rwn/Projects/web2py/gluon/restricted.py", line 192, in restricted
exec ccode in environment
File
"/home/rwn/Projects/web2py/applications/g_bender/controllers/default.py", line
132, in <module>
File "/home/rwn/Projects/web2py/gluon/globals.py", line 137, in <lambda>
self._caller = lambda f: f()
File
"/home/rwn/Projects/web2py/applications/g_bender/controllers/default.py", line
66, in update
form=SQLFORM.factory(db.person, db.affiliation, db.address, db.card,
record=record)
File "/home/rwn/Projects/web2py/gluon/sqlhtml.py", line 1226, in factory
return SQLFORM(DAL(None).define_table(table_name, *fields), **attributes)
File "/home/rwn/Projects/web2py/gluon/sqlhtml.py", line 772, in __init__
default = record[fieldname]
File "/home/rwn/Projects/web2py/gluon/dal.py", line 3701, in __getitem__
return dict.__getitem__(self, key)
KeyError: 'organization'
I think the error is because I'm only passing a record from db.person.
So how do I actually retrieve the same record set I entered using the
technique presented in "one form for multiple tables"? I couldn't find a
relevant example to follow in the book.
Thanks.