SQL Alchemy

Dynamically constructing filters based on string input using SQLAlchemy

Here I am going to write a dynamic filter. This filter is made for python 3. It will take query or model class and filter condtion as input, It will return filtered query based on those filter condition. This is constructed using this SO answer. Function: class DynamicFilter(ModelHelper): def __init__(self, query=None, model_class=None, filter_condition=None): super().__init__(*args, **kwargs) self.query = query self.model_class = model_class self.filter_condition = filter_condition def get_query(self): ''' Returns query with all the objects :return: '''…

Keep reading