class Comment(db.Model): " a comment on an article " __tablename__ = 'comments' id = db.Column(db.Integer, primary_key=True) html = db.Column(db.Text()) timestamp = db.Column(db.DateTime, default=datetime.utcnow) disabled = db.Column(db.Boolean, default=False) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) article_id = db.Column(db.Integer, db.ForeignKey('articles.id')) def __repr__(self): return "{}\n(authored by: {} at {})".format(html, author.username, timestamp)
class Comment(db.Model, CRUDMixin): """ comments on the articles """ __tablename__ = 'comments' html = db.Column(db.Text()) timestamp = db.Column(db.DateTime, default=datetime.utcnow) disabled = db.Column(db.Boolean, default=False) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) article_id = db.Column(db.Integer, db.ForeignKey('articles.id')) def __repr__(self): return "{}\n(authored by: {} at {})".format(html, author.username, timestamp)
class Article(db.Model): " database representation of an article " __tablename__ = 'articles' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(128)) subtitle = db.Column(db.String(512)) body = db.Column(db.Text()) views = db.Column(db.Integer, default=1) category = db.Column(db.String(64)) timestamp = db.Column(db.DateTime, default=datetime.utcnow) visited_users = db.Column(db.PickleType()) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) @hybrid_method def popularity(self, gravity=1.8): seconds = (self.timestamp - datetime.utcnow()).total_seconds() hours = seconds / 3600 return (self.views - 1) / (hours + 2)**gravity @popularity.expression def popularity(self, gravity=1.8): seconds = func.extract('epoch', self.timestamp - func.now()) hours = seconds / 3600 return (self.views - 1) / func.power((hours + 2), gravity) def __repr__(self): return '{}\n{}\n{}\n'.format(self.title, self.subtitle, self.body)
class Article(db.Model, CRUDMixin): """ articles in the database """ __tablename__ = 'articles' title = db.Column(db.String(128)) subtitle = db.Column(db.String(512)) body = db.Column(db.Text()) views = db.Column(db.Integer, default=1) timestamp = db.Column(db.DateTime, default=datetime.utcnow) visited_users = db.Column(db.Integer) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) tags = db.relationship(Tag, lambda: article_tags, collection_class=set, backref=db.backref('articles', collection_class=set)) _tags = association_proxy('tags', 'name', creator=Tag.get_unique) @hybrid_method def popularity(self, gravity=2): seconds = (self.timestamp - datetime.utcnow()).total_seconds() hours = seconds / 3600 return (self.views - 1) / (hours + 2)**gravity @popularity.expression def popularity(self, gravity=2): seconds = func.extract('epoch', self.timestamp - func.now()) hours = seconds / 3600 return (self.views - 1) / func.power((hours + 2), gravity) def __repr__(self): return '{}\n{}\n{}\n'.format(self.title, self.subtitle, self.body)
seconds = func.extract('epoch', self.timestamp - func.now()) hours = seconds / 3600 return (self.views - 1) / func.power((hours + 2), gravity) def __repr__(self): return '{}\n{}\n{}\n'.format(self.title, self.subtitle, self.body) class Comment(db.Model, CRUDMixin): """ comments on the articles """ __tablename__ = 'comments' html = db.Column(db.Text()) timestamp = db.Column(db.DateTime, default=datetime.utcnow) disabled = db.Column(db.Boolean, default=False) author_id = db.Column(db.Integer, db.ForeignKey('users.id')) article_id = db.Column(db.Integer, db.ForeignKey('articles.id')) def __repr__(self): return "{}\n(authored by: {} at {})".format(html, author.username, timestamp) article_tags = db.Table( 'article_tags', db.Column('article_id', db.Integer, db.ForeignKey(Article.id), primary_key=True), db.Column('tag_id', db.Integer, db.ForeignKey(Tag.id), primary_key=True))