python-3.xflaskflask-admin

how to show relationship data in human readable text in flask-admin page


My admin pageenter image description here when I want to edit User, I see that Serv - orm.relation("Services", back_populates='user') shows in non-human readable text. This is my model:

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

What function I have to include?


Solution

  • You haven't defined either a __repr__ method or __str__ method for your Services model.

    See this SO QA, Difference between str and repr?. Note the summary in the answer:

    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.