column_choices = {
'state': [(0, 'OK'), (1, 'Failed'), (2, 'Unknown')]
}
form_overrides = dict(
state=SelectField
)
form_args = dict(
state=dict(coerce=int, choices=[(0, 'OK'), (1, 'Failed'), (2, 'Unknown')], validators=[Optional()])
)
想让 state 这个字段保存 0,1,2 这样的整形,但是在列表上展示的时候显示对应 choice 的 text。
我按上面这样写,列表刷新直接报错
TypeError: 'NoneType' object is not iterable
但是改成
choices=[('0', 'OK'), ('1', 'Failed'), ('2', 'Unknown')]
就没有问题,不过列表页就不能显示 choice 对应的 text 了,而是值。