how to pass a not like operator in a sqlalchemy ORM query

Jérôme Pigeot picture Jérôme Pigeot · Feb 16, 2011 · Viewed 30.1k times · Source

I've got a query:

MyModel.query.filter(Mymodel.name.contains('a_string'))

I need to do the same query but with the negation (a not like operator) but didn't find any operator matching my need in the SQLAlchemy documentation.

Is there any way to do it without using the sql part of SQLAlchemy???

Answer

Maxim Sloyko picture Maxim Sloyko · Feb 16, 2011

Just negate the filter:

MyModel.query.filter(sqlalchemy.not_(Mymodel.name.contains('a_string')))