flask-sqlalchemy
flask-sqlalchemy copied to clipboard
Support __iter__ on Pagination instances.
I never remember to call .items, and I was just reminded of this when getting a new developer spun up. Instead of:
for obj in MyModel.query.paginate(1).items: pass
I expect:
for obj in MyModel.query.paginate(1): pass
... because SQLAlchemy's query API does this everywhere. This fails, because a Pagination instance is not iterable.
Current discussion on #pocoo irc: no harm in making it iterable, but at that point you might just use .offset().limit() on the SQLAlchemy query interface. If Pagination is used generally, outside of a SQL context, then an iterable interface would be more useful.
fixed in #1087