mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-14 07:39:03 +00:00
SCHEMA CHANGE: Add comment_count to Torrent
with a helper function on Torrent to update the count.
This commit is contained in:
@@ -67,6 +67,8 @@ class Torrent(db.Model):
|
||||
uploader_ip = db.Column(db.Binary(length=16), default=None, nullable=True)
|
||||
has_torrent = db.Column(db.Boolean, nullable=False, default=False)
|
||||
|
||||
comment_count = db.Column(db.Integer, default=0, nullable=False, index=True)
|
||||
|
||||
created_time = db.Column(db.DateTime(timezone=False), default=datetime.utcnow, nullable=False)
|
||||
updated_time = db.Column(db.DateTime(timezone=False),
|
||||
default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
||||
@@ -107,6 +109,10 @@ class Torrent(db.Model):
|
||||
def __repr__(self):
|
||||
return '<{0} #{1.id} \'{1.display_name}\' {1.filesize}b>'.format(type(self).__name__, self)
|
||||
|
||||
def update_comment_count(self):
|
||||
self.comment_count = Comment.query.filter_by(torrent_id = self.id).count()
|
||||
return self.comment_count
|
||||
|
||||
@property
|
||||
def created_utc_timestamp(self):
|
||||
''' Returns a UTC POSIX timestamp, as seconds '''
|
||||
@@ -149,6 +155,8 @@ class Torrent(db.Model):
|
||||
if self.uploader_ip:
|
||||
return str(ip_address(self.uploader_ip))
|
||||
|
||||
# Flag getters and setters below
|
||||
|
||||
@property
|
||||
def anonymous(self):
|
||||
return self.flags & TorrentFlags.ANONYMOUS
|
||||
@@ -197,6 +205,8 @@ class Torrent(db.Model):
|
||||
def complete(self, value):
|
||||
self.flags = (self.flags & ~TorrentFlags.COMPLETE) | (value and TorrentFlags.COMPLETE)
|
||||
|
||||
# Class methods
|
||||
|
||||
@classmethod
|
||||
def by_id(cls, id):
|
||||
return cls.query.get(id)
|
||||
|
||||
Reference in New Issue
Block a user