Is there no example how to do this ? I mean this is not such an exotic case that you want to create a edit form for some record in more than one table and locate the fields you want them to show up and pre-filled with data that is already in the db (edit form).
But it seems that either you can do the one or the other thing in web2py. There is an example of SQLFORM.factory in the manual (P.201) which simply doesn't work for me when it comes to the call to form.accept(). The effect is always a key error "no_table" in sqlhtml.py and I have no idea how to prevent this. Seems like SQLFORM.factory is more hairy than I thought and I wonder why it needs to be used in case I want to locate the fields myself. Becoming desperate here, switching forth and back between SQLFORM, FORM and SQLFORM.factory, trying to squeeze the default forms in a HTML table (which ncauses two separate forms), using HTML Helpers in the controller (which prevents style attributes for table like "width"). What is so special in this use case that it can't be done smoothly like the other things in web2py ? best Stefan On 26 Okt., 12:55, znafets <znaf...@googlemail.com> wrote: > the call to form.accepts fails with "key error" no-table ... after the > form gets submitted... > > if form.accepts(request.vars, session): > > On 26 Okt., 11:05, znafets <znaf...@googlemail.com> wrote: > > > Hi Thadeus, weheh, > > > if I make it read like this: > > > req_user_id = request.args[0] > > > user = db((db.user.id == req_user_id) & > > (db.addr.user == req_user_id)).select()[0] > > > db.user.id.default = user.user.id > > db.user.name.default = user.user.name > > db.user.email.default = user.user.email > > db.addr.city.default = user.addr.city > > > form = SQLFORM.factory(db.user.name, db.user.rname, > > db.addr.city) > > > pre populating works. > > > @weheh: can you post an example how you take it from there with the > > custom.form technics ? > > > thanls > > Stefan > > > On 26 Okt., 07:06, weheh <richard_gor...@verizon.net> wrote: > > > > This is an unsolicited testimonial. I've been doing this kind of > > > multi- > > > table-form thing now for about a month or two. I collect data for > > > specific fields for multiple tables (2 or 3 at a time) using > > > SQLFORM.factory forms and use form.custom.begin ... form.custom.end > > > in > > > my views. At first, it felt all cold, slobbery and gross. Utterly > > > unintuitive. A total WET (Widespread Echoed Text) LICK (Long > > > Incredibly > > > Chaotic Kode). But now that I've sort'a mastered it and refactored > > > everything, it feels kind'a like a warm DRY KISS. I agree with > > > Thadeus, it ain't pretty, at least not as pretty as straight SQLFORM > > > or FORM or CRUD. But it works. And it gives you complete flexibility > > > in terms of form structure and layout while maintaining a separate > > > database structure that's designed for efficiency rather than easy > > > form layout. Is there a better way? I dunno ... my mind can't lift > > > heavy loads like that any more. Anyway, that's as far as my 2 cents > > > goes. Cheers. > > > > On Oct 25, 2:11 pm, Thadeus Burgess <thade...@thadeusb.com> wrote: > > > > > Ah yes, forgot to add the field to the end of it. Thats what happens > > > > when I > > > > write code in email :) > > > > > SQLFORM.factory(db.user.name, db.address.street) > > > > > -Thadeus > > > > > On Sun, Oct 25, 2009 at 12:38 PM, mdipierro <mdipie...@cs.depaul.edu> > > > > wrote: > > > > > > This > > > > > > > SQLFORM.factory( > > > > > > db.user, db.address > > > > > > ) > > > > > > will not quire work because both tables contain an Id field. I think > > > > > you need to explicitly list the fields to you want. > > > > > > Massimo > > > > > > On Oct 25, 11:50 am, Thadeus Burgess <thade...@thadeusb.com> wrote: > > > > > > znafets, Keeping the thread in this post... > > > > > > > user = db((db.user.id == request.id) & (db.address.id_user == > > > > > > request.id > > > > > > )).select() > > > > > > > db.user.id.default = user.id > > > > > > db.user.name.default = user.name > > > > > > db.user.email.default = user.email > > > > > > > SQLFORM.factory( > > > > > > db.user, db.address > > > > > > ) > > > > > > > Is there another way of doing this? To me, this is not DRY or KISS. > > > > > > > -Thadeus > > > > > > > On Sat, Oct 24, 2009 at 3:20 PM, Renato-ES-Brazil > > > > > > <caliari.ren...@gmail.com>wrote: > > > > > > > > Massimo, > > > > > > > > Sorry, your message to Thadeus, which also answered my question, > > > > > > > appeared only after, when I sent my question to this topic. > > > > > > > > My example had just one table because it was a simple test with > > > > > > > SQLFORM.factory. > > > > > > > > I thought it worked this way that you mentioned, but when I saw > > > > > > > that > > > > > > > the SQLFORM.factory allows to send some parameters like > > > > > > > "db.table.field" instead of using Field(), I got confused. :-) > > > > > > > > On 24 out, 18:07, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > > > A SQLFORM.factory has no knowledge of the underlying database. > > > > > > > > If you > > > > > > > > use SQLFORM.factory you should do the inserts/update manually. > > > > > > > > > In your case your form involves a single table so you should > > > > > > > > just use > > > > > > > > crud.create or crud.update > > > > > > > > use db.table.field.writable and db.table.field.readable and > > > > > > > > db.table.field.default to change the behavior of the form. > > > > > > > > > On Oct 24, 3:02 pm, Renato-ES-Brazil <caliari.ren...@gmail.com> > > > > > wrote: > > > > > > > > > > Massimo, > > > > > > > > > > I tried to use SQLFORM.factory just for tests: > > > > > > > > > > def edit(): > > > > > > > > > task_id = request.args(0) > > > > > > > > > task=db(db.task.id==task_id).select()[0] > > > > > > > > > form=SQLFORM.factory(db.task.title, db.task.description, > > > > > > > > > record=task) > > > > > > > > > if form.accepts(request.vars, session): > > > > > > > > > response.flash = 'form accepted' > > > > > > > > > elif form.errors: > > > > > > > > > response.flash = 'form has errors' > > > > > > > > > else: > > > > > > > > > response.flash = '' > > > > > > > > > return dict(form=form) > > > > > > > > > > The message "form accepted" was shown but the record was not > > > > > updated. > > > > > > > > > What should I do for work? > > > > > > > > > > On 24 out, 17:32, Thadeus Burgess <thade...@thadeusb.com> > > > > > > > > > wrote: > > > > > > > > > > > >>>form=SQLFORM.factory(db. > > > > > > > > > > > > table1.field1,db.table2.field2) > > > > > > > > > > > Does this allow for the data to be inserted into the > > > > > > > > > > database? I > > > > > > > would try > > > > > > > > > > it right now but busy cleaning the home :) > > > > > > > > > > > -Thadeus > > > > > > > > > > > On Sat, Oct 24, 2009 at 1:35 PM, mdipierro < > > > > > mdipie...@cs.depaul.edu> > > > > > > > wrote: > > > > > > > > > > > > What is wrong with this? > > > > > > > > > > > > form=SQLFORM.factory(db.table1.field1,db.table2.field2) > > > > > > > > > > > > On Oct 24, 1:28 pm, Thadeus Burgess > > > > > > > > > > > <thade...@thadeusb.com> > > > > > wrote: > > > > > > > > > > > > As far as [1], use custom form > > > > > > > > > > > > >http://web2py.com/AlterEgo/default/show/205 > > > > > > > > > > > > > As far as [2], you could use SQLFORM.factory() or just a > > > > > straight > > > > > > > FORM() > > > > > > > > > > > > object, and populate their default from the database, > > > > > > > > > > > > and on > > > > > > > accepts you > > > > > > > > > > > > would have to insert them seperately into the database. > > > > > > > > > > > > > I think this is a limitation of web2py that needs some > > > > > > > > > > > > work, > > > > > Too > > > > > > > often do > > > > > > > > > > > I > > > > > > > > > > > > have to break DRY just to get data from two tables into > > > > > > > > > > > > one > > > > > form, > > > > > > > its not > > > > > > > > > > > > pretty, and difficult to maintain. > > > > > > > > > > > > > I find myself, almost not even using SQLFORM or CRUD > > > > > > > > > > > > anymore, > > > > > > > just > > > > > > > > > > > because I > > > > > > > > > > > > need specific fine grained control. > > > > > > > > > > > > > -Thadeus > > > > > > > > > > > > > On Sat, Oct 24, 2009 at 1:22 PM, znafets < > > > > > znaf...@googlemail.com> > > > > > > > wrote: > > > > > > > > > > > > > ot a table with user data and a table with address > > > > > > > > > > > > > data > > > > > > > referencing > > > > > > > > > > > > > the user > > > > > > > > > > > > > Now I would like to cre- Hide quoted text - > > > > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---