diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-04-30 10:58:54 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-04-30 10:58:54 +0200 |
commit | f03a9825fc047e2371356d7b1784c65835756c55 (patch) | |
tree | defe05beca3b794e1988787586a584e131689b4c /pyaggr3g470r/models.py | |
parent | Added comments. (diff) | |
download | newspipe-f03a9825fc047e2371356d7b1784c65835756c55.tar.gz newspipe-f03a9825fc047e2371356d7b1784c65835756c55.tar.bz2 newspipe-f03a9825fc047e2371356d7b1784c65835756c55.zip |
Link between next and previous articles.
Diffstat (limited to 'pyaggr3g470r/models.py')
-rw-r--r-- | pyaggr3g470r/models.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/pyaggr3g470r/models.py b/pyaggr3g470r/models.py index f4aa0521..6c6df180 100644 --- a/pyaggr3g470r/models.py +++ b/pyaggr3g470r/models.py @@ -28,7 +28,7 @@ __license__ = "GPLv3" import json from datetime import datetime -from sqlalchemy import desc +from sqlalchemy import asc, desc from werkzeug import generate_password_hash, check_password_hash from flask.ext.login import UserMixin @@ -123,6 +123,18 @@ class Article(db.Model): user_id = db.Column(db.Integer, db.ForeignKey('user.id')) feed_id = db.Column(db.Integer, db.ForeignKey('feed.id')) + def previous_article(self): + """ + Returns the previous article (older). + """ + return Article.query.filter(Article.date < self.date, Article.feed_id == self.feed_id).order_by(desc("Article.date")).first() + + def next_article(self): + """ + Returns the next article (newer). + """ + return Article.query.filter(Article.date > self.date, Article.feed_id == self.feed_id).order_by(asc("Article.date")).first() + def __repr__(self): return json.dumps({ "title": self.title, |