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 <[email protected]> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.