Peewee 和 Flask-admin:我无法在管理员视图中显示引用表中的字段



我无法显示引用表中的选定字段。我正在使用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')}}

我得到这个:烧瓶管理问题

但是我不需要我的用户的ID,而是电子邮件...谢谢

解决方案:

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')}}

相关内容

  • 没有找到相关文章

最新更新