iehoshia
(Josías)
July 1, 2020, 5:04pm
1
Hi,
I’m working in a blog with tryton_flask and tryton. I want to add a pagination option to the main page but I don’t know how to do the query with FROM and TO arguments.
I’m using the follow code to get the records. Now I want to get 1-24, 25-49 range of records.
entries = Entry.search([('published','=',True)])
Thanks in advance.
lukio
(Luciano Rossi)
July 1, 2020, 6:07pm
2
Hi! I believe that you can pass offset , limit , order and count parameters to search method. Check the doc of search method
1 Like
pokoli
(Sergi Almacellas Abellana)
July 1, 2020, 8:42pm
3
There is flask extensions to manage pagination called flask-paginate , which can be used with flask-tryton.
Here is some example:
from flask_paginate import Pagination, get_page_args
@app.route('index')
def index(self):
page, per_page, offset = get_page_args()
domain = [ ]
records = Model.search(domain, order=[('date', 'DESC'), ('id', 'DESC')],
offset=offset, limit=per_page)
count = Model.search(domain, count=True)
pagination = Pagination(
page=page, total=count, search=False)
return render_template(
'template.html', records=records, pagination=pagination)
Hope it helps!
3 Likes
system
(system)
Closed
August 1, 2020, 3:21pm
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.