如何让flask-admin在显示外键字段时使用替代表示法? [英] How to tell flask-admin to use alternative representation when displaying Foreign Key Fields?

查看:517
本文介绍了如何让flask-admin在显示外键字段时使用替代表示法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何告诉flask-admin在这个RoleUser链接表中使用外键字段的替代表示形式?

解决方案

最简单的方法是添加 __ str __ 方法(Python 2的 __ unicode __ )到模型中。

  class Role(db.Model):
#snip
def __str __(self):
返回self.name


How can I tell flask-admin to use an alternative representation for Foreign Key Fields such as the following in this RoleUser link table?

解决方案

The simplest way is to add __str__ methods (__unicode__ for Python 2) to your models.

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

这篇关于如何让flask-admin在显示外键字段时使用替代表示法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆