先上官方文档(这是 ModelView中自己 Configuration Attributes):
When your forms contain foreign keys, have those related models loaded via ajax, using:
`form_ajax_refs = {
'user': {
'fields': ['first_name', 'last_name', 'email'],
'page_size': 10
}
}
`
To filter the results that are loaded via ajax, you can use:
`form_ajax_refs = {
'active_user': QueryAjaxModelLoader('user', db.session, User,
filters=["is_active=True", "id>1000"])
}`
第一个例子,我用自己的测试成功了;
第二个例子,我读了 QueryAjaxModelLoader函数源码定义也不太理解:
1.'active_user' 是谁的属性?
2.User是ModelView绑定的类还是外键相关的类?
3.'user'是ModelView绑定的类的属性,还是User的属性?
4.User类的定义应该是什么样子的?
'user'是ModelView绑定的类的属性,还是User的属性?