【问题标题】:How to tell flask-admin to use alternative representation when displaying Foreign Key Fields?如何告诉烧瓶管理员在显示外键字段时使用替代表示?
【发布时间】:2016-01-10 06:25:38
【问题描述】:

如何告诉 flask-admin 使用外键字段的替代表示,例如此 RoleUser 链接表中的以下内容?

【问题讨论】:

    标签: python flask flask-admin


    【解决方案1】:

    最简单的方法是将__str__ 方法(__unicode__ 用于 Python 2)添加到您的模型中。

    class Role(db.Model):
        # snip
        def __str__(self):
            return self.name
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      • 2012-08-24
      相关资源
      最近更新 更多