change form type flask from text to selection flask admin

Solutions on MaxInterview for change form type flask from text to selection flask admin by the best coders in the world

showing results for - "change form type flask from text to selection flask admin"
Arianna
11 Mar 2020
1   class MyModel(db.Model):
2       id = db.Column(db.Integer, primary_key=True)
3       my_field = db.Column(db.String(128))  # Field I would like to be choices
4
5
6    class MyModelView(ModelView):
7        """
8        Admin manager for MyModel
9        """
10
11            form_choices = {
12                 'my_field': [
13                     ('choice_1', 'Choice 1'),
14                     ('choice_2', 'Choice 2'),
15                     ('choice_3', 'Choice 3'),
16                     ('choice_4', 'Choice 4'),
17                     ('choice_5', 'Choice 5')
18                ]
19           }
20
21        def __init__(self):
22            super(MyModelView, self).__init__(MyModel, db.session)
23