Is there any way to get the prev/next records from a SqlAlchemy query? Like so:
record.id
record.next.id
record.prev.id
I could add the prev/next methods to each model myself, but I'm wondering if there is already some automagical way that I overlooked. The web application in question is written in Pylons.
Edit: This is probably a dirty hack, but it works. I imported the sqlalchemy Session object into my model and did this:
def next(self):
return Session.query(Blog).filter(Blog.id > self.id).order_by(Blog.id).first()
def prev(self):
return Session.query(Blog).filter(Blog.id < self.id).order_by(desc(Blog.id)).first()