mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-12 09:00:40 +00:00
add user_corpus m2m relationship
This commit is contained in:
@ -257,7 +257,7 @@ class Avatar(HashidMixin, FileMixin, db.Model):
|
||||
# Primary key
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
# Foreign keys
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), unique=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
@ -276,7 +276,16 @@ class Avatar(HashidMixin, FileMixin, db.Model):
|
||||
**self.file_mixin_to_json_serializeable()
|
||||
}
|
||||
return json_serializeable
|
||||
|
||||
|
||||
|
||||
corpus_followers = db.Table(
|
||||
'corpus_followers',
|
||||
db.Model.metadata,
|
||||
db.Column('user_id', db.ForeignKey('users.id'), primary_key=True),
|
||||
db.Column('corpus_id', db.ForeignKey('corpora.id'), primary_key=True)
|
||||
)
|
||||
|
||||
|
||||
class User(HashidMixin, UserMixin, db.Model):
|
||||
__tablename__ = 'users'
|
||||
# Primary key
|
||||
@ -327,6 +336,13 @@ class User(HashidMixin, UserMixin, db.Model):
|
||||
cascade='all, delete-orphan',
|
||||
lazy='dynamic'
|
||||
)
|
||||
followed_corpora = db.relationship(
|
||||
'Corpus',
|
||||
secondary=corpus_followers,
|
||||
primaryjoin=(corpus_followers.c.user_id == id),
|
||||
backref=db.backref('followers', lazy='dynamic'),
|
||||
lazy='dynamic'
|
||||
)
|
||||
jobs = db.relationship(
|
||||
'Job',
|
||||
backref='user',
|
||||
|
Reference in New Issue
Block a user