watson.db.utils¶
- class watson.db.utils.Pagination(query, page=1, limit=20)[source]¶
Provides simple pagination for query results.
- query¶
Query
The SQLAlchemy query to be paginated
- page¶
int
The page to be displayed
- limit¶
int
The maximum number of results to be displayed on a page
- total¶
int
The total number of results
- items¶
list
The items returned from the query
Example:
# within controller query = session.query(Model) paginator = Pagination(query, limit=50) # within view {% for item in paginator %} {% endfor %} <div class="pagination"> {% for page in paginator.iter_pages() %} {% if page == paginator.page %} <a href="#" class="current">{{ page }}</a> {% else %} <a href="#">{{ page }}</a> {% endif %} {% endfor %} </div>
- has_next[source]¶
Return whether or not there are more pages from the currently displayed page.
Returns: boolean
- has_previous[source]¶
Return whether or not there are previous pages from the currently displayed page.
Returns: boolean