Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

change form type flask from text to selection flask admin

   class MyModel(db.Model):
       id = db.Column(db.Integer, primary_key=True)
       my_field = db.Column(db.String(128))  # Field I would like to be choices


    class MyModelView(ModelView):
        """
        Admin manager for MyModel
        """

            form_choices = {
                 'my_field': [
                     ('choice_1', 'Choice 1'),
                     ('choice_2', 'Choice 2'),
                     ('choice_3', 'Choice 3'),
                     ('choice_4', 'Choice 4'),
                     ('choice_5', 'Choice 5')
                ]
           }

        def __init__(self):
            super(MyModelView, self).__init__(MyModel, db.session)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #change #form #type #flask #text #selection #flask #admin
ADD COMMENT
Topic
Name
8+7 =