Pagination with Pony ORM Pagination with Pony ORM flask flask

Pagination with Pony ORM


You can query a pagination

q = models.select(d for d in models.Thingy)page = 1count = q.count()results_of_first_page = q.page(page, 20)pages = int(count/20)if pages > 20:    pages = 20


Fast solution, may be not the best

@app.route('/persons-list/<int:page>') def persons_list(page):    LIMIT = 10    items = select(p for p in models.Person)    return render_template('persons_list.html',                            maxpage=items.count()//LIMIT,                            page=page,                            items=items.page(page, LIMIT))

in template:

{% if maxpage > 1 %}    {% if page - 1 >= 1 %}        <a href="{{ url_for('persons_list', page=page-1) }}"><</a>    {% endif %}    Page {{ page }} of {{ maxpage }}    {% if page + 1 <= maxpage %}        <a href="{{ url_for('persons_list', page=page+1) }}">></a>    {% endif %}{% endif %}