我无法显示从引用表中选择的字段。我正在使用peewee,Flask-admin和Flask-Security。
在Flask-admin视图中,显示了外键字段的值,但是我需要引用表(电子邮件)中的其他字段。
我的矮人模型定义:
class User(BaseModel, UserMixin):
"""User of my app"""
email = TextField(unique=True)
password = TextField()
class UserDevice(BaseModel):
"""Table with all devices added and owned by users."""
device_uniqueid = CharField(primary_key=True)
device_user = ForeignKeyField(User, null=True, backref='userdevices')
class UserDeviceAdmin(ModelView):
"""Flask-admin view for managing devices"""
column_list = ['device_uniqueid', 'device_user']
column_sortable_list = ('device_uniqueid', ('device_user', User.email))
form_ajax_refs = {'device_user': {'fields': (User.email, 'email')}}
我得到这个: flask-admin problem
但是我不需要我的用户ID,而是电子邮件...谢谢
答案 0 :(得分:0)
解决方案:
class UserDeviceAdmin(ModelView):
"""Flask-admin view for managing devices"""
column_list = ['device_uniqueid', 'device_user.email']
column_sortable_list = ('device_uniqueid', ('device_user', User.email))
form_ajax_refs = {'device_user': {'fields': (User.email, 'email')}}