状态字段显示 3 个选项,但在提交时始终显示“不是有效选择”,无论选择哪个。
from website import app, db
from flask.ext import admin
from flask.ext.admin.contrib import sqlamodel
from wtforms.fields import SelectField
class Users(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(160), unique=True)
status = db.Column(db.Integer)
def __repr__(self):
return self.name
class UsersAdmin(sqlamodel.ModelView):
form_overrides = dict(status=SelectField)
form_args = dict(
status=dict(
choices=[(0, 'Regular'), (1, 'Guest'), (2, 'Banned')],
))
admin = admin.Admin(app, 'Admin')
admin.add_view(UsersAdmin(Users, db.session))