Here's a solution offered by Denes a while back: 
https://groups.google.com/d/msg/web2py/pso1oLF-bKU/uCIXtLcjQ9kJ
 

On Monday, July 11, 2011 7:50:15 AM UTC-4, niknok wrote:

> 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/ 
> <http://127.0.0.1:8000/admin/default/edit/g_bender/controllers/default.py>rwn/Projects/web2py/applications/g_bender/controllers/default.py"
>  <http://127.0.0.1:8000/admin/default/edit/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/ 
> <http://127.0.0.1:8000/admin/default/edit/g_bender/controllers/default.py>rwn/Projects/web2py/applications/g_bender/controllers/default.py"
>  <http://127.0.0.1:8000/admin/default/edit/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.
>
>
>
>
>

Reply via email to