forked from gergely/calendar-social
Add a __repr__ method to the Profile method
This commit is contained in:
parent
acb7566d1b
commit
2136546390
@ -165,7 +165,9 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
|
|||||||
id = db.Column(db.Integer(), primary_key=True)
|
id = db.Column(db.Integer(), primary_key=True)
|
||||||
|
|
||||||
#: The ID of the local user this profile belongs to
|
#: 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
|
#: The username this profile belongs to. If ``None``, `user_id` must be set
|
||||||
username = db.Column(db.String(length=50), nullable=True)
|
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
|
#: The display name
|
||||||
display_name = db.Column(db.Unicode(length=80), nullable=False)
|
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'<Profile {self.id}(@{username}{domain})>'
|
||||||
|
|
||||||
|
|
||||||
class Event(db.Model):
|
class Event(db.Model):
|
||||||
"""Database model for events
|
"""Database model for events
|
||||||
|
Loading…
Reference in New Issue
Block a user