>From http://stackoverflow.com/q/10117143/937891
I'm trying to exclude posts which have a tag named meta from my selection, by: meta_id = db(db.tags.name == "meta").select().first().id not_meta = ~db.posts.tags.contains(meta_id) posts=db(db.posts).select(not_meta) But those posts still show up in my selection. What is the right way to write that expression? My tables look like: db.define_table('tags', db.Field('name', 'string'), db.Field('desc', 'text', default="") ) db.define_table('posts', db.Field('title', 'string'), db.Field('message', 'text'), db.Field('tags', 'list:reference tags'), db.Field('time', 'datetime', default=datetime.utcnow()) ) *UPDATE:* I just tried posts=db(not_meta).select() as suggested by @Anthony, but it gives me a Ticket with the following Traceback: Traceback (most recent call last): File "E:\Programming\Python\web2py\gluon\restricted.py", line 205, in restricted exec ccode in environment File "E:/Programming/Python/web2py/applications/vote_up/controllers/default.py", line 391, in <module> File "E:\Programming\Python\web2py\gluon\globals.py", line 173, in <lambda> self._caller = lambda f: f() File "E:/Programming/Python/web2py/applications/vote_up/controllers/default.py", line 8, in index posts=db(not_meta).select()#orderby=settings.sel.posts, limitby=(0, settings.delta) File "E:\Programming\Python\web2py\gluon\dal.py", line 7578, in select return adapter.select(self.query,fields,attributes) File "E:\Programming\Python\web2py\gluon\dal.py", line 3752, in select (items, tablename, fields) = self.select_raw(query,fields,attributes) File "E:\Programming\Python\web2py\gluon\dal.py", line 3709, in select_raw filters = self.expand(query) File "E:\Programming\Python\web2py\gluon\dal.py", line 3589, in expand return expression.op(expression.first) File "E:\Programming\Python\web2py\gluon\dal.py", line 3678, in NOT raise SyntaxError, "Not suported %s" % first.op.__name__ SyntaxError: Not suported CONTAINS