I have a few questions regarding how to do pagination with gae. test code:
for i in range(0, 6): MyClass(myProperty=unicode(i)).put() q = MyClass.all() cursor = None print haveMore = True batchSize = 2 i = 1 while haveMore: print 'Batch', i i = i + 1 result_set = q.with_cursor(start_cursor=cursor).fetch(batchSize) for obj in result_set: print obj.myProperty cursor = q.cursor() print cursor haveMore = True if len(result_set) == batchSize else False
output:
Batch 1 0 1 E9oBTgoMdGVzdGJlZC10ZXN0GgdNeUNsYXNzIUNVUlNPUiFqHWoMdGVzdGJlZC10ZXN0cg0LEgdNeUNsYXNzGAIMggENCxIHTXlDbGFzcxgCDOABABQ= Batch 2 2 3 E9oBTgoMdGVzdGJlZC10ZXN0GgdNeUNsYXNzIUNVUlNPUiFqHWoMdGVzdGJlZC10ZXN0cg0LEgdNeUNsYXNzGAQMggENCxIHTXlDbGFzcxgEDOABABQ= Batch 3 4 5 E9oBTgoMdGVzdGJlZC10ZXN0GgdNeUNsYXNzIUNVUlNPUiFqHWoMdGVzdGJlZC10ZXN0cg0LEgdNeUNsYXNzGAYMggENCxIHTXlDbGFzcxgGDOABABQ= Batch 4
Questions:
- First of all, how is the result set progressing when the same cursor is used in different iterations of the for loop?
- How to fix the edge of the edge? The for loop should end after three iterations. Package 4 is empty.
- How to go back in gae (i.e. return instead of the next)?
source share