I have a Flask app with which I would like to display paginated tables of data from a MongoDB Collection. However, there are potentially very many documents in this collection, so I would like to be loading them lazily - only loading the ones which are about to be displayed.
My problem is that on one page in my app, I would like to paginate:
Stuff.objects()
But on different pages I would like to paginate:
Stuff.objects(__raw__=query) or Stuff.objects(message__in=Message.objects(__raw__=query))
Calling any of those particular functions automatically loads all of the relevant objects into memory (as I discovered by running locals()) so I need to paginate the calls with:
Stuff.objects().skip(number).limit(pagelength), or
Stuff.objects(__raw__=query).skip(number).limit(pagelength)
So it would seem that I need a Paginator class which I can simply pass Report into, then somehow specify the query information.
Can anyone recommend a solution?
Try using the paginator from flask-mongoengine You can use it like so:
paginator = Pagination(Post.objects, 1, 10)
print paginator.items
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With