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" does not work as it's intended only for fields defined as list types, - the alternative is to use "belongs" as Niphlod suggested yesterday. --