From 213654639068158048a7023480d3c0c64de2803e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 9 Jul 2018 09:55:55 +0200 Subject: [PATCH] Add a __repr__ method to the Profile method --- calsocial/models.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/calsocial/models.py b/calsocial/models.py index 69e3ba1..ba07ded 100644 --- a/calsocial/models.py +++ b/calsocial/models.py @@ -165,7 +165,9 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods id = db.Column(db.Integer(), primary_key=True) #: The ID of the local user this profile belongs to - user_id = db.Column(db.Integer(), db.ForeignKey('users.id'), nullable=True) + user_id = db.Column(db.Integer(), db.ForeignKey('users.id'), nullable=True, unique=True) + + user = db.relationship(User, backref=db.backref('profile', lazy='dynamic')) #: The username this profile belongs to. If ``None``, `user_id` must be set username = db.Column(db.String(length=50), nullable=True) @@ -176,6 +178,16 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods #: The display name display_name = db.Column(db.Unicode(length=80), nullable=False) + def __repr__(self): + if self.user: + username = self.user.username + domain = '' + else: + username = self.username + domain = '@' + self.domain + + return f'' + class Event(db.Model): """Database model for events