To use
cls.query
you need to assign query_property to your model classes!
You might want to use this in other model classes as well, so you might want to do this in your base model class somewhere in your model/__init__.py :
Base.query = Session.query_property()
Then you can simply write:
cls.query.filter(...)
Note that you no longer specify the object for the query, which is automatically done using the query_property mechanism.
source share