Skip to content

Commit

Permalink
Fixing ajax casting
Browse files Browse the repository at this point in the history
Right now, Ajax was not able to search for an integer for example. It was a problem for id fields.
This makes sure ILIKE will work with such field.
  • Loading branch information
Charles-Go authored May 31, 2018
1 parent ee59ae5 commit 725d4ba
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flask_admin/contrib/sqla/ajax.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sqlalchemy import or_, and_
from sqlalchemy import or_, and_, cast
from sqlalchemy.types import String

from flask_admin._compat import as_unicode, string_types
from flask_admin.model.ajax import AjaxModelLoader, DEFAULT_PAGE_SIZE
Expand Down Expand Up @@ -65,7 +66,7 @@ def get_one(self, pk):
def get_list(self, term, offset=0, limit=DEFAULT_PAGE_SIZE):
query = self.session.query(self.model)

filters = (field.ilike(u'%%%s%%' % term) for field in self._cached_fields)
filters = (cast(field, String).ilike(u'%%%s%%' % term) for field in self._cached_fields)
query = query.filter(or_(*filters))

if self.filters:
Expand Down

0 comments on commit 725d4ba

Please sign in to comment.