On Friday, November 20, 2015 at 5:54:26 AM UTC-5, Massimiliano wrote:
>
> If I’m not missing something you can you do:
>
> table = ‘memos’
> field = ‘construction_site’
> param1 = 1
> param2 = 2
>
> query = (db[table][field] == param1)
> query = query | (db[table][field] == param2)
>
Note, you can also do:
query = query1
query |= query2
query &= query3
Also, to be clear, if the table and field names are fixed, you don't need
to assign them to variables and use db[tablename][fieldname] syntax -- you
can just use db.tablename.fieldname.
Finally, depending on what you are looping over, you may be able to
simplify further -- for example:
query = reduce(lambda a, b: a | b,
[db.mytable.myfield.startswith(prefix) for prefix in
list_of_prefixes])
The above generates a list of queries based on the same field but matching
different prefixes, and then joins all the queries with the "or" operator.
Finally, if you just want to select a set of records that exactly matches
one of several possible values on some field, you can simply use the
.belongs method:
rows = db(db.mytable.myfield.belongs([list, of, values])).select()
Anthony
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.