sqlalchemy - How to add pagination to query to return 10 results per page -


i need add pagination web form ( @ moment have returned database there much).

    result = []     session = session()     index = 1     user in session.query(usermodel).order_by(desc(usermodel.age)).all():         result.append({'username' : user.username,                        'nation' : user.nation,                         'age' : user.age,                          'rank' : index})         index = index + 1 

i need put pagination (10 results per page, ordered age). how add pagination query ?

use limit(n) , offset (m) next n rows offset m. code should follows:

result = [] session = session() index = 1 user in session.query(usermodel).order_by(desc(usermodel.age)).offset(m).limit(n).all():     result.append({'username' : user.username,                    'nation' : user.nation,                     'age' : user.age,                      'rank' : index})     index = index + 1 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -