Add grid filter which treats empty string as NULL
This commit is contained in:
parent
512405f01f
commit
401cba23b7
2 changed files with 21 additions and 0 deletions
|
@ -334,6 +334,24 @@ class AlchemyStringFilter(AlchemyGridFilter):
|
|||
))
|
||||
|
||||
|
||||
class AlchemyEmptyStringFilter(AlchemyStringFilter):
|
||||
"""
|
||||
String filter with special logic to treat empty string values as NULL
|
||||
"""
|
||||
|
||||
def filter_is_null(self, query, value):
|
||||
return query.filter(
|
||||
sa.or_(
|
||||
self.column == None,
|
||||
sa.func.trim(self.column) == ''))
|
||||
|
||||
def filter_is_not_null(self, query, value):
|
||||
return query.filter(
|
||||
sa.and_(
|
||||
self.column != None,
|
||||
sa.func.trim(self.column) != ''))
|
||||
|
||||
|
||||
class AlchemyByteStringFilter(AlchemyStringFilter):
|
||||
"""
|
||||
String filter for SQLAlchemy, which encodes value as bytestring before
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue