Skip to content Skip to sidebar Skip to footer

Search On Non-text Column In Flask-admin

I have a sqlalchemy model: class Multicast(db.Model): __tablename__ = 'multicast' id = Column(Integer, primary_key=True) addr = Column(Inet) name = Column(Unicode(6

Solution 1:

I found some solution. I overrided get_list method in MulticastView. I copied all source code from ModelView and added a line in search criteria code:

filter_stmt.append(func.text(Multicast.addr).like(stmt))

It works!

Solution 2:

Another option here is to modify the allowed_search_types for the MulticastView class:

classMulticastView(ModelView):
    allowed_search_types = (
        mongoengine.StringField,
        mongoengine.URLField,
        mongoengine.EmailField,
        mongoengine.Inet
    )
    ...

Post a Comment for "Search On Non-text Column In Flask-admin"