1

I have a field that currently the user can just type into but I have ENUM in my table, I would like it so they can only select one or the other as an option. Currently im trying to use base_filters, I have everything imported correctly, just not working

class FrankView(ModelView):
    datamodel = SQLAInterface(Frank)
    list_columns = ['id', 'name']
    add_columns = ['id', 'name']
    edit_columns = ['id', 'name']

    base_filters = [['name', FilterEqual, 'Maven']]
Theo
  • 71
  • 8

1 Answers1

1

Not sure why are you wanting to use the base_filter in this case, but the basic usage of ENUM in F.A.B. is something like this:

from flask_appbuilder import Model, ModelView
from sqlalchemy import Column, Integer, Enum
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_appbuilder.models.sqla.filters import FilterEqual

class Frank(Model):
    __tablename__='frank'

    id = Column(Integer, primary_key=True, nullable=False)
    name_as_enum=Column(Enum('Maven','Not Maven'), nullable=False, default='Maven')

class FrankView(ModelView):
    datamodel = SQLAInterface(Frank)
    list_columns = ['id', 'name_as_enum']
    add_columns = ['id', 'name_as_enum']
    edit_columns = ['id', 'name_as_enum']

    base_filters = [['name_as_enum', FilterEqual, 'Maven']]

If you are wanting to use base_filters don't forget to import the filters you are trying to use.

Loki
  • 134
  • 1
  • 2
  • 8