Hi everybody,

I'm building a page that will search for rows in a database table
based on optional URL parameters, or return all rows if no parameters
are given. However, I'm having trouble finding a good way to build up
the query without having an existing Query object to start with.
Web2py currently lets me do something like this:

q = (db.person.height > 5)
q = q & (db.person.height < 6)
db(q).select()


But I'd like to be able to do something like this (in pseudocode):

q = EmptyQuery(defaultTable=db.person)
if request.vars.minheight:
  q = q & (db.person.height > request.vars.minheight)
if request.vars.maxheight:
  q = q & (db.person.height < request.vars.maxheight)

people = db(q).select()

so that if no parameters are given, it will select all from db.person,
but you can optionally filter by min and max height.

Is there an easy way to do this in web2py?

Thanks!
Kevin

Reply via email to