Maybe: query &= ~db.mytable.id.belongs(blacklist)
or just: query = query & another_condition On Friday, October 28, 2011 3:45:45 PM UTC-4, Cliff wrote: > > I'm pretty sure I saw a thread about this, but I can't find it. > > I need to do something like > > query = ((db.mytable.id==somevalue) & (db.mytable.active==True)) > > if blacklist: > query.append(~db.mytable.id.belongs(blacklist)) > > How do I do this? > > The reason I'm doing this is psycopg2 raises an exception if the query > contains NOT IN().

