def exact_filter(query, model, filters, legal_keys):
 filter_dict = {}
 for key in legal_keys:
  if (key not in filters):
   continue
  value = filters.pop(key)
  if isinstance(value, (list, tuple, set, frozenset)):
   column_attr = getattr(model, key)
   query = query.filter(column_attr.in_(value))
  else:
   filter_dict[key] = value
 if filter_dict:
  query = query.filter_by(**filter_dict)
 return query

def exact_filter ( query , model , filters , legal_keys ) : filter_dict = { } for key in legal_keys : if ( key not in filters ) : continue value = filters . pop ( key ) if isinstance ( value , ( list , tuple , set , frozenset ) ) : column_attr = getattr ( model , key ) query = query . filter ( column_attr . in_ ( value ) ) else : filter_dict [ key ] = value if filter_dict : query = query . filter_by ( ** filter_dict ) return query
applies exact match filtering to a query .