dynamic queries

63 views
Skip to first unread message

dave

unread,
Jul 29, 2012, 2:12:22 AM7/29/12
to
I have something like   
    qset=db()
   
if arg1 == "xyz": qset=qset(db.abc.id > 0)
   
if arg2 == "abc": qset=qset(db.abc.age > 5)
    x
= qset.select()
   


now I want to pass x to SQLFORM.grid something like this
return SQLFORM.grid(x)
but this does not work because qset.select returns all the rows with all the columns I think, I know that SQLFORM.grid accepts a table or a query so how can I pass x to it?

dave

unread,
Jul 29, 2012, 7:37:52 AM7/29/12
to
   I solved this problem by using the code below, instead of using the above code, if anyone comes across this problem
   
queries=[]
if arg1 == "xyz": queries.append(db.abc.id > 0)
if arg2 == "abc": queries.append(db.abc.age > 5)
query
= reduce(lambda a,b:(a&b),queries)


and you can insert this query into SQLFORM.grid(query)
Reply all
Reply to author
Forward
0 new messages