diff options
Diffstat (limited to 'grumpy/models.py')
-rw-r--r-- | grumpy/models.py | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/grumpy/models.py b/grumpy/models.py index 241afde..49b58ee 100644 --- a/grumpy/models.py +++ b/grumpy/models.py @@ -30,6 +30,10 @@ package_herds = db.Table('package_herds', db.Model.metadata, db.Column('package_id', db.Integer, db.ForeignKey('packages.id')), db.Column('herd_id', db.Integer, db.ForeignKey('herds.id')) ) +package_users = db.Table('package_users', db.Model.metadata, + db.Column('package_id', db.Integer, db.ForeignKey('packages.id')), + db.Column('user_id', db.Integer, db.ForeignKey('users.id')) + ) class Developer(db.Model): """Represents developers in the system""" @@ -106,27 +110,6 @@ class Ebuild(db.Model): def __repr__(self): return '<%s> - %s' % (self.__class__.__name__, self.cpv) -class Favorite(db.Model): - """Represents packages that user can add in their watch list.""" - - __tablename__ = 'favorites' - __table_args__ = ( - db.UniqueConstraint('package_id', 'user_id'), - {}) - - id = db.Column('id', db.Integer, primary_key=True) - _package = db.Column('package_id', db.Integer, db.ForeignKey('packages.id')) - _user = db.Column('user_id', db.Integer, db.ForeignKey('users.id')) - - package = db.relationship("Package") - user = db.relationship("User", backref=db.backref('favorites')) - - def __init__(self, package): - self.package = package - - def __repr__(self): - return '<%s> - %s' % (self.__class__.__name__, self.package.cp) - class Herd(db.Model): """Represents herds in the system""" @@ -166,6 +149,8 @@ class Package(db.Model): ebuilds = db.relationship(Ebuild, backref='package', \ cascade='all, delete-orphan', \ collection_class=column_mapped_collection(Ebuild.cpv)) + favorites = db.relationship("User", secondary=package_users, + backref='favorites') def __init__(self, ebuild_src, mtime=time.time()): self.key = ebuild_src.key |