python - How to create custom filter_by in SQLAlchemy -


i want create more complex filter_by - in way if pass kwargs , values of none, don't want included in filter. i'm not sure how override filter_by globally.

effectively i'm looking is.

data = {'is_enabled': true, 'city': 'sf', 'address': none} query.smart_filter(data) 

and smart_filter excludes 'address' field , calls filter_by 'is_enabled' , 'city' values.

is there way build this?

subclass sqlalchemy.orm.query, add smart_filter method, , pass new class sessionmaker. along lines:

class myquery(query):     def smart_filter(self, **kwargs):         kwargs = {key: value key, value in kwargs.items()                    if value not none}         return self.filter_by(**kwargs)  session = sessionmaker(query_cls=myquery) 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -