See http://groups.google.com/group/web2py/msg/4a9e84fb5ceb2e4f It only works if there are no common field names. I have added this to the book.
On Dec 5, 5:07 pm, tomt <tom_tren...@yahoo.com> 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 <villa...@gmail.com> 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" <nat...@freezable.com> 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 <tom_tren...@yahoo.com> 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 > >