Thanks for looking Kenneth.
Should it be a record id? From the book (and epydocs):
record = db.person(request.args(0))
form = SQLFORM(db.person, record)
where record is a Row object and it works correctly. I tried your
suggestion to pass an id but got a "KeyError:'name'" error.
Sorry for being a bit thick here, but correct me if I'm wrong, but the
"one form for multiple tables" section in the book uses
SQLFORM.factory which, I now realize, doesn't accept a record
argument. Or does it?
On Jul 11, 9:06 pm, Kenneth Lundström <[email protected]>
wrote:
> 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)
>
> The problem is that your are giving SQLFORM a row object as you should
> give it an ID.
> record = db.person(request.args(0)) creates a row object so instead o:
> form=SQLFORM.factory(db.person, db.affiliation, db.address,
> db.card, record)
> try:
> form=SQLFORM.factory(db.person, db.affiliation, db.address,
> db.card, record[0].id)
>
> or maybe even add an small check that request.args is correct:
> record = db.person(request.args(0))
> if len(record):
> form=SQLFORM.factory(db.person, db.affiliation, db.address,
> db.card, record)
> else:
> response.flash=(T('No record with that ID found'))
>
> Kenneth
>
>
>
>
>
>
>
>
>
> > Traceback (most recent call last):
> > File "/home/rwn/Projects/web2py/gluon/restricted.py", line192, 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>,
> > line132, in<module>
> > File "/home/rwn/Projects/web2py/gluon/globals.py", line137, 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>,
> > line66, in update
> > form=SQLFORM.factory(db.person, db.affiliation, db.address, db.card,
> > record=record)
> > File "/home/rwn/Projects/web2py/gluon/sqlhtml.py", line1226, in factory
> > return SQLFORM(DAL(None).define_table(table_name, *fields),
> > **attributes)
> > File "/home/rwn/Projects/web2py/gluon/sqlhtml.py", line772, in __init__
> > default = record[fieldname]
> > File "/home/rwn/Projects/web2py/gluon/dal.py", line3701, 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.