Fix back_populate relationships

This commit is contained in:
Ymage 2022-12-22 22:50:01 +01:00
parent 8dd03a4d85
commit 7d153932b3
2 changed files with 3 additions and 2 deletions

View File

@ -5,7 +5,7 @@ class Role(db.Model):
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(64), index=True, unique=True) name = db.Column(db.String(64), index=True, unique=True)
description = db.Column(db.String(128)) description = db.Column(db.String(128))
users = db.relationship('User', backref='role', lazy=True) users = db.relationship('User', back_populates='role', lazy=True)
apikeys = db.relationship('ApiKey', back_populates='role', lazy=True) apikeys = db.relationship('ApiKey', back_populates='role', lazy=True)
def __init__(self, id=None, name=None, description=None): def __init__(self, id=None, name=None, description=None):
@ -20,4 +20,4 @@ class Role(db.Model):
self.description = description self.description = description
def __repr__(self): def __repr__(self):
return '<Role {0}r>'.format(self.name) return '<Role {0}>'.format(self.name)

View File

@ -34,6 +34,7 @@ class User(db.Model):
otp_secret = db.Column(db.String(16)) otp_secret = db.Column(db.String(16))
confirmed = db.Column(db.SmallInteger, nullable=False, default=0) confirmed = db.Column(db.SmallInteger, nullable=False, default=0)
role_id = db.Column(db.Integer, db.ForeignKey('role.id')) role_id = db.Column(db.Integer, db.ForeignKey('role.id'))
role = db.relationship('Role', back_populates="users", lazy=True)
accounts = None accounts = None
def __init__(self, def __init__(self,