Creating One-to-one Relationship Flask-SQLAlchemy
I am trying to create a one-to-one relationship between a Department & Ticket table. This way when looking inside of Flask-Admin a user would be able to see the Department name
Solution 1:
Define function __repr__
of Department
.
class Department(db.Model)
# ... column definition
def __repr__(self):
return self.name
The __repr__
will show the name of department instead the inner representation of object.
PS: uselist=0
is the key to define a one to one relationship in SQLAlchemy.
Post a Comment for "Creating One-to-one Relationship Flask-SQLAlchemy"