Treat filter by "contains X Y" as "contains X and contains Y".

This commit is contained in:
Lance Edgar 2015-08-21 23:43:19 -05:00
parent c9b01f6061
commit 920f0144c2

View file

@ -287,7 +287,8 @@ class AlchemyStringFilter(AlchemyGridFilter):
"""
if value is None or value == '':
return query
return query.filter(self.column.ilike('%{0}%'.format(value)))
return query.filter(sa.and_(
*[self.column.ilike('%{0}%'.format(v)) for v in value.split()]))
def filter_does_not_contain(self, query, value):
"""
@ -300,7 +301,8 @@ class AlchemyStringFilter(AlchemyGridFilter):
# include things which are nothing at all, in our result set.
return query.filter(sa.or_(
self.column == None,
~self.column.ilike('%{0}%'.format(value)),
sa.and_(
*[~self.column.ilike('%{0}%'.format(v)) for v in value.split()]),
))