Try this:

animals = request.vars.animals
if not isinstance(animals, list):
    animals = [animals]
res = db(db.table.field.belongs(animals)).select(db.table.ALL)



On Mar 29, 10:59 pm, pacopyc <paco...@gmail.com> wrote:
> With this code works, but I don't like this:
>
> if type(animals) == str:
>   res = db(db.table.field==animals).select(db.table.ALL)
> else:
>   res = db(db.table.field.belongs(animals)).select(db.table.ALL)
>
> Can you say me a better method?
>
> Thank you
>
> On 29 Mar, 13:29, pacopyc <paco...@gmail.com> wrote:
>
> > Hi, I've a problem with belongs. I've a page with a list of checkbox
> > (dog, cat, mouse, ...). For example If I choose dog and cat I'd like
> > execute:
>
> > select * from table where field in ('dog', 'cat')
>
> > I've written this code:
>
> > animals = request.vars.animals
> > res = db(db.table.field.belongs(animals)).select(db.table.ALL)
>
> > This works very good!!!
> > But If I choose only dog (for example) the code don't work. If I print
> > sql query I get this
>
> > select * from table where field in (do)
>
> > There aren't characters " ' " and last letter " g ". I don't
> > understand. Can you help me?
>
> > Thank you very much

-- 
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