Re: [web2py] Re: Help with db query

2012-11-09 Thread Wikus van de Merwe
Assuming that request.args contains the right values, this should work: category = request.args[1].replace('_', ' ') query = (db.Supplements.Category == category) & ((db.Supplements.Users == request.args[0]) | (db.Supplements.Users == "Both")) records = db(query).select() Notes: - "contains" doe

Re: [web2py] Re: Help with db query

2012-11-07 Thread hasan alnator
Dear Joe , I tried this : values = [] values.append(request.args(0)) values.append('Both') sup = db((db.Supplements.Category == (request.args(1)).replace('_',' ')) & (db.Supplements.Users.contains(values))).select(db.Supplements.ALL) And it didnt do anything !!! i dont u

Re: [web2py] Re: Help with db query

2012-11-07 Thread Joe Barnhart
There is a Field function called "contains()" which would be useful here. It is described in the online book here: http://www.web2py.com/books/default/chapter/29/06#like,-regexp,-startswith,-contains,-upper,-lower Your query would be something like: db.table.Field2.contains( [ 'value1', 'valu

Re: [web2py] Re: Help with db query

2012-11-07 Thread Niphlod
field in something is NOT supported (Man, you should check both the web2py book and general python syntax, or you'll loose a lot of time) Your prototype in python pointed to have something ORed, i.e. if request.args(0) is None, then slip it in 'Both'. What instead you're trying to achieve is qu

Re: [web2py] Re: Help with db query

2012-11-07 Thread hasan alnator
and i even tried : items =[] items.append(request.args(0)) items.append('Both') db( (db.table.Field1 == value) & (db.table.Field2 in items)) regards, On Wed, Nov 7, 2012 at 12:56 PM, hasan alnator wrote: > Dear Joe , > > What i want to do is to have a query like this : > > db( (db.table.Fie

Re: [web2py] Re: Help with db query

2012-11-07 Thread hasan alnator
Dear Joe , What i want to do is to have a query like this : db( (db.table.Field1 == value) & (db.table.Field2 == value or value)) i tried it i get no errors but its now working Regards On Wed, Nov 7, 2012 at 10:10 AM, Joe Barnhart wrote: > I see -- you're right. > > The request.args structur

[web2py] Re: Help with db query

2012-11-07 Thread Joe Barnhart
I see -- you're right. The request.args structure is a List() object which web2py defines to retrieve values without the exception if it doesn't exist. It has some additional interesting capabilities... You can define a default value, such as this: request.args(0,default='Both') This will

[web2py] Re: Help with db query

2012-11-06 Thread Niphlod
> One more point -- your "request.args(1)" should be "request.args[1]" > (with square brackets). The first form calls request.args as a function > and passes it the value "1". The second form treats request.args as a > Storage object and asks for the subscript "1". > > -- Joe Barnhart > > N

[web2py] Re: Help with db query

2012-11-06 Thread Joe Barnhart
Hi Hassan -- In web2py, the Field object is a subclass of Expression. That's how you can use it with comparison symbols. When you pass it to the database connection as a function, it produces a Set which loosely represents the rows of the database that will eventually be "selected" (but the s

[web2py] Re: Help with db query

2012-11-06 Thread Niphlod
don't get it. you are doing str(request.args(0)) . If request.args(0) is None (i.e. there is no request.args[0]), str(None) returns 'None' as a string. 'None' as a string is True, so it doesn't get to be "ORed" with 'Both'. >>> None or 'Both' 'Both' >>> str(None) or 'Both' 'None' >>> None and st

[web2py] Re: Help with db query

2012-11-06 Thread Hassan Alnatour
How Can i do : (query) & (db.table.Field == i or s) ??? regards On Tuesday, November 6, 2012 7:33:09 PM UTC+2, Hassan Alnatour wrote: > > Dear ALL , > > i am trying to do this : > > sup = db( > (db.Supplements.Category == (request.args(1)).replace('_',' ')) & (db. > Supplements.Users == st