How to tell flask-admin to use alternative representation when displaying Foreign Key Fields?

社会主义新天地 提交于 2019-11-28 10:25:37

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/34702734/how-to-tell-flask-admin-to-use-alternative-representation-when-displaying-foreig

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!