def model_filter(query, model, **filters):
    for key, value in filters.items():
        if isinstance(key, basestring):
            if hasattr(model, key):
                col_attr = getattr(model, key)
            else:
                continue
        else:
            col_attr = key
        condition = _model_condition(col_attr, value)
        if condition is not None:
            query = query.filter(condition)
    return query
Append conditons to query for each possible column.
dataset/ETHPy150Open openstack/compass-core/compass/db/api/utils.py/model_filter