M
M
Mike2016-12-20 19:40:22
Flask
Mike, 2016-12-20 19:40:22

How to do a search in flask-admin?

I have a simple model.

class Words(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    russia = db.Column(db.String(50))
    english = db.Column(db.String(50))
    buttons = db.Column(db.Text())
    
    def __init__(self, russia=None, english=None, buttons=None):
        self.russia = russia
        self.english = english
        self.buttons = buttons
        
####### Admin ######### Admin ########## Admin ###########################
admin = Admin(app, name="Demo", template_mode='bootstrap3')
admin.add_view(ModelView(Words, db.session))


How can I search for 'russia' in the admin panel?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mike, 2016-12-21
@google_online

Everything turned out to be simple and not so difficult. Maybe someone needs. Here is the code.

###### Models ######### Models ######## Models ###########
class Words(db.Model):
    __tablename__ = 'words'
    id = db.Column(db.Integer, primary_key = True)
    russia = db.Column(db.String(50))
    english = db.Column(db.String(50))
    buttons = db.Column(db.Text())
     
    def __init__(self, russia=None, english=None, buttons=None):
        self.russia = russia
        self.english = english
        self.buttons = buttons
 
class Mytools(ModelView):
    column_searchable_list = ['russia']
     
####### Admin ######### Admin ########## Admin ###########################
admin = Admin(app, name="Demo", template_mode='bootstrap3')
admin.add_view(Mytools(Words, db.session))

Here I just read https://flask-admin.readthedocs.io/en/latest/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question