How to use pagination with tryton_flask

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.

Hi! I believe that you can pass offset, limit, order and count parameters to search method. Check the doc of search method

1 Like

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

It works like a charm!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.