Answers for "change form type flask from text to selection flask admin"

0

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)
Posted by: Guest on December-17-2020

Python Answers by Framework

Browse Popular Code Answers by Language