diff options
author | Mart Raudsepp <leio@gentoo.org> | 2016-12-04 08:24:39 +0200 |
---|---|---|
committer | Mart Raudsepp <leio@gentoo.org> | 2016-12-04 08:24:39 +0200 |
commit | a0e5f8b3559f243236d9dd1170a00d4405042631 (patch) | |
tree | e5008df5b6104ee008dc43b6acccbada73f8ba85 | |
parent | sync: Initial projects syncing to DB without members (diff) | |
download | grumpy-a0e5f8b3559f243236d9dd1170a00d4405042631.tar.gz grumpy-a0e5f8b3559f243236d9dd1170a00d4405042631.tar.bz2 grumpy-a0e5f8b3559f243236d9dd1170a00d4405042631.zip |
models: Add association table and ORM relationship between projects and members
-rw-r--r-- | backend/lib/models.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/backend/lib/models.py b/backend/lib/models.py index bc6cd20..f842a8a 100644 --- a/backend/lib/models.py +++ b/backend/lib/models.py @@ -31,6 +31,11 @@ class PackageVersion(db.Model): def __repr__(self): return "<PackageVersion '%s/%s-%s'>" % (self.package.category.name, self.package.name, self.version) +maintainer_project_membership_rel_table = db.Table('maintainer_project_membership_rel', + db.Column('project_id', db.Integer, db.ForeignKey('maintainer.id')), + db.Column('maintainer_id', db.Integer, db.ForeignKey('maintainer.id')), +) + class Maintainer(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.Unicode(50), nullable=False, unique=True) @@ -39,5 +44,12 @@ class Maintainer(db.Model): url = db.Column(db.Unicode()) description = db.Column(db.Unicode(500)) + members = db.relationship("Maintainer", + secondary=maintainer_project_membership_rel_table, + primaryjoin=id==maintainer_project_membership_rel_table.c.project_id, + secondaryjoin=id==maintainer_project_membership_rel_table.c.maintainer_id, + backref='projects') + # projects relationship backref ^^ + def __repr__(self): return "<Maintainer %s '%s'>" % ("project" if self.is_project else "individual", self.email) |