The status field shows the 3 options, but always displays "Not a valid choice" on submisison, whichever is chosen.
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))
It is likely that the choices are being sent as unicode string while your status field in db is integer. Can you try the following:
form_args = dict(
status=dict(
choices=[(0, 'Regular'), (1, 'Guest'), (2, 'Banned')],coerce=int
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With