I have a class which is an ndb.Model. I am trying to add pagination so I added this:
@classmethod
def get_next_page(cls, cursor):
q = cls.query()
q_forward = q.order(cls.title)
if cursor:
cursor = ndb.datastore_query.Cursor(cursor)
objects, cursor, more = q_forward.fetch_page(10, start_cursor=cursor)
return objects, cursor.urlsafe(), more
However, fetch_page ALWAYS returns more == false and cursor is always just empty. But if I instead of cursor use offset=5 or offset=10 or whatever it works just fine. The cursor does not update so it always starts from the first item.
I am testing this locally with stub context.
I wonder what am I missing? I'm very new to this.
I believe it should be
ndb._datastore_query.Cursor(see reference) or just dondb.CursorIf the cursor came from UI and you had previously made it
urlsafe, then you should be doingndb._datastore_query.Cursor(urlsafe=cursor)orndb.Cursor(urlsafe=cursor)Also, when you don't have a cursor, make sure it's explicitly set to
Noneor just dondb.Cursor()orndb._datastore_query.Cursor()