diff options
author | Mart Raudsepp <leio@gentoo.org> | 2016-12-07 03:55:18 +0200 |
---|---|---|
committer | Mart Raudsepp <leio@gentoo.org> | 2016-12-07 03:55:18 +0200 |
commit | ed46487bc107c4f404d23e6429e0e4050616459b (patch) | |
tree | c67502fbf820f4c59b40a16ff83a121daecd34f6 | |
parent | models: Add description and last_sync_ts columns for Package (diff) | |
download | grumpy-ed46487bc107c4f404d23e6429e0e4050616459b.tar.gz grumpy-ed46487bc107c4f404d23e6429e0e4050616459b.tar.bz2 grumpy-ed46487bc107c4f404d23e6429e0e4050616459b.zip |
models: Add package maintainers relationship table and ORM relationships
-rw-r--r-- | backend/lib/models.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/backend/lib/models.py b/backend/lib/models.py index e06dcf8..ba20622 100644 --- a/backend/lib/models.py +++ b/backend/lib/models.py @@ -10,6 +10,11 @@ class Category(db.Model): def __repr__(self): return "<Category %r>" % self.name +package_maintainer_rel_table = db.Table('package_maintainer_rel', + db.Column('package_id', db.Integer, db.ForeignKey('package.id')), + db.Column('maintainer_id', db.Integer, db.ForeignKey('maintainer.id')), +) + class Package(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Unicode(128), nullable=False) @@ -17,6 +22,9 @@ class Package(db.Model): category = db.relationship('Category', backref=db.backref('packages', lazy='dynamic')) description = db.Column(db.Unicode(500)) last_sync_ts = db.Column(db.TIMESTAMP, nullable=False, default=datetime.utcfromtimestamp(0)) + maintainers = db.relationship("Maintainer", + secondary=package_maintainer_rel_table, + backref='directly_maintained_packages') @property def full_name(self): @@ -54,6 +62,7 @@ class Maintainer(db.Model): secondaryjoin=id==maintainer_project_membership_rel_table.c.maintainer_id, backref='projects') # projects relationship backref ^^ + # directly_maintained_packages backref - list of packages maintained directly by given project or individual maintainer (as opposed to a bigger list that includes packages maintained by parent/child projects or projects the given individual maintainer is part of) def __repr__(self): return "<Maintainer %s '%s'>" % ("project" if self.is_project else "individual", self.email) |