如何在 flask-admin 页面中以人类可读文本显示关系数据
how to show relationship data in human readable text in flask-admin page
我的管理页面,see screenshot,
当我想编辑用户时,我看到 Serv - orm.relation("Services", back_populates='user')
以非人类可读的文本显示。
这是我的模型:
class User(SqlAlchemyBase, UserMixin, SerializerMixin):
__tablename__ = 'users'
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, nullable=False)
..
serv = orm.relation("Services", back_populates='user')
def __repr__(self):
return self.name
我必须包含什么功能?
您还没有为您的 Services
模型定义 __repr__
方法或 __str__
方法。
查看此 SO QA,Difference between str and repr?。请注意答案中的摘要:
Implement __repr__
for any class you implement. This should be second
nature. Implement __str__
if you think it would be useful to have a
string version which errs on the side of readability.
我的管理页面,see screenshot,
当我想编辑用户时,我看到 Serv - orm.relation("Services", back_populates='user')
以非人类可读的文本显示。
这是我的模型:
class User(SqlAlchemyBase, UserMixin, SerializerMixin):
__tablename__ = 'users'
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True, nullable=False)
..
serv = orm.relation("Services", back_populates='user')
def __repr__(self):
return self.name
我必须包含什么功能?
您还没有为您的 Services
模型定义 __repr__
方法或 __str__
方法。
查看此 SO QA,Difference between str and repr?。请注意答案中的摘要:
Implement
__repr__
for any class you implement. This should be second nature. Implement__str__
if you think it would be useful to have a string version which errs on the side of readability.