I have a model which uses an enum to define an access level as follows:
class DevelModelView(ModelView):
edit_modal = True
def is_accessible(self):
return current_user.is_authenticated and current_user.access is AccessLevel.DEVEL
class DevelStaffModelView(DevelModelView):
column_editable_list = ['access']
column_filters = ['access']
column_searchable_list = ['login', 'email']
form_choices = {'access': [(AccessLevel.DEVEL.name, AccessLevel.DEVEL.value),
(AccessLevel.ADMIN.name, AccessLevel.ADMIN.value),
(AccessLevel.STAFF.name, AccessLevel.STAFF.value)]}
The enum definition is below...
class AccessLevel(Enum):
DEVEL = 'Developer'
ADMIN = 'Administrator'
STAFF = 'Staff Member'
Using the form_choices attribute I was able to show in both the modal and the editable column choices in value form (IE: Developer) but unfortunately the display is still using the name (IE: Name).
To clarify, I'm essentially asking if there is anyway to have Flask Admin display the value of an enum as opposed to the name by default in the display table. Thank you in advance...
Also providing the Staff model just in case it is helpful...
class Staff(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
login = db.Column(db.String(64), unique=True)
_password = db.Column(db.String(128))
email = db.Column(db.String(100))
access = db.Column('access', db.Enum(AccessLevel))
@hybrid_property
def password(self):
return self._password
@password.setter
def password(self, plaintext):
self._password = bcrypt.generate_password_hash(plaintext)
def check_password(self, plaintext):
return bcrypt.check_password_hash(self._password, plaintext)
def __str__(self):
return "%s: %s (%s)" % (self.access.name, self.login, self.email)