Thanks for the example and the reference. - Tom
On Dec 6, 5:58 pm, villas <[email protected]> wrote: > Hi tomt > > I believe it takes the fields from the specified source table and > lines them up with a target table. Any fields which don't match and > the id are discarded. > > What Denes means is that it wouldn't work when for example you use > form.vars from multiple tables which have some identical field names. > In that case, when it filters through the form.vars it doesn't know > which field comes from which table. > > Hope that's right :) > > -D > > On Dec 5, 10:07 pm, tomt <[email protected]> wrote: > > > Hi, > > > I'm unfamiliar with _filter_fields. I couldn't find it in the manual > > but eventually found it in the source in gluon/tools.py. > > Am I correct in assuming it is intended to return everything but the > > id field from a record? (I've just started to learn python) > > > Is there some documentation available for this? I've tried some of the > > urls in the help and resources post: > > http://web2py.com/examples/default/dal > > http://web2py.com/examples/default/api > > http://web2py.com/examples/default/tools > > > But I just get "invalid function" > > > Thanks in advance, > > - Tom > > > On Dec 5, 7:00 am, villas <[email protected]> wrote: > > > > Hi Nathan > > > > Just a small point, I tried your code example and it seems you have to > > > set id==None otherwise it tries to add a duplicate row with the same > > > id. > > > > Anyway, I thought you also might like this alternative using > > > _filter_fields, just because it's shorter. Maybe it's got other > > > issues, but it seems to work! > > > > def things(): > > > form = SQLFORM(db.things) > > > if form.accepts(request.vars,session): > > > response.flash = 'Added a thing' > > > if request.vars.dupe: > > > > db.things.insert(**db.things._filter_fields(db.things(request.vars.dupe))) > > > things = db(db.things.id>0).select() > > > return dict(form=form,things=things) > > > > Best regards, > > > -D > > > > On Dec 4, 3:30 am, "mr.freeze" <[email protected]> wrote: > > > > > Here is an example: > > > > > Model > > > > ----- > > > > db.define_table('things',Field('name',requires=IS_NOT_EMPTY()), > > > > Field('age','integer'),Field('weight','double')) > > > > db.things.id.represent = lambda v: A(v,_href=URL(vars=dict(dupe=v)), > > > > _onclick='return confirm("Copy > > > > %s?")' % v) > > > > > Controller > > > > ---------- > > > > def index(): > > > > form = SQLFORM(db.things) > > > > if form.accepts(request.vars,session): > > > > response.flash = 'Added a thing' > > > > if request.vars.dupe: > > > > record = db.things(request.vars.dupe) > > > > vals = {} > > > > for k,v in record.items(): > > > > if k in db.things.fields: > > > > vals[k] = v > > > > db.things.insert(**vals) > > > > things = db(db.things.id>0).select() > > > > return dict(form=form,things=things) > > > > > On Dec 3, 6:12 pm, tomt <[email protected]> wrote: > > > > > > Hi, > > > > > > I've started to write a simple application to learn web2py. I am using > > > > > SQLFORM to insert, modify and delete records. So far everything is > > > > > working as planned. > > > > > > I would like to give the user the ability add a new record as a copy > > > > > of an existing one. The idea is that the user would view an existing > > > > > record, modify a couple fields, and select 'copy' which result in > > > > > adding a new record. > > > > > > I assume that this requires additional code, and I was hoping that > > > > > someone would suggest an example, or let me know if SQLFORM can do > > > > > this automatically. > > > > > > Thanks in advance, > > > > > > - Tom > >

