Make User.profile a single object instead of a list

Because it’s a one-to-one relationship anyway, what’s the use of lists here?
This commit is contained in:
Gergely Polonkai 2018-07-09 13:03:24 +02:00
parent ad53608966
commit 1c2635045b
2 changed files with 4 additions and 6 deletions

View File

@ -256,12 +256,10 @@ class CalendarSocialApp(Flask):
from .models import Profile, User from .models import Profile, User
try: profile = current_user.profile
profile = Profile.query.join(User).filter(User.username == username.lower()).one()
except NoResultFound: if profile is None:
abort(404) abort(404)
except MultipleResultsFound:
abort(500)
return render_template('profile-details.html', profile=profile) return render_template('profile-details.html', profile=profile)

View File

@ -167,7 +167,7 @@ class Profile(db.Model): # pylint: disable=too-few-public-methods
#: 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, unique=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')) user = db.relationship(User, backref=db.backref('profile', uselist=False))
#: 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)