nice work Richard, can you create a plug-in with the code in a model
module
e.g. model/plugin_dalhelper.py
this would make it easy for me an others to install use and improve
(if there is still a need for it) your code
also if you write updates I guess i could just reinstall the plug-in
and have an updated version of it?!

On Jan 29, 6:06 am, Richard <richar...@gmail.com> wrote:
> thanks that's much neater.
>
> > does not do what you think it does.
>
> can you explain? It worked for my test cases...
>
> > record = db(logic).select(table['id']).first()
>
> I noticed you removed the ID selection part - is there any efficiency
> gained in just selecting the ID?
>
> Richard
>
> On Jan 29, 12:06 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
>
>
> > This
>
> >     logic = None
> >     for field, value in fields.items():
> >         e = table[field] == value
> >         logic = e if logic is None else logic & e
> >     record = db(logic).select(table['id']).first()
>
> > does not do what you think it does.
>
> > I think you want:
>
> >     logic=reduce(lambda a,b:a&b,[table[k]==fields[k] for k in fields])
> >     record = db(logic).select().first()
>
> > On Jan 28, 6:24 am, Richard <richar...@gmail.com> wrote:
>
> > > I want to get the ID of a record with certain fields, and create it if
> > > not already existing. Is there a shortcut for this common operation?
> > > In Django it is called "get_or_create()"
>
> > > Also, is there a shortcut for update_or_create()?
>
> > > Thanks,
> > > Richard

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@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.

Reply via email to