开发者

Extend django.core.paginator Paginator to work with Google App Engine

开发者 https://www.devze.com 2022-12-27 19:32 出处:网络
How would one extend the Paginat开发者_如何学Pythonor class in django.core.paginator to work with Google App Engine queries?The following changes are necessary:

How would one extend the Paginat开发者_如何学Pythonor class in django.core.paginator to work with Google App Engine queries?


The following changes are necessary:

from django.core.paginator import Paginator, Page

class GAEPaginator(Paginator):
    def page(self, number):
      "Returns a Page object for the given 1-based page number."
      number = self.validate_number(number)
      offset = (number - 1) * self.per_page
      if offset+self.per_page + self.orphans >= self.count:
        top = self.count
      return Page(self.object_list.fetch(self.per_page, offset), number, self)

It would be nice of Paginator was aware of GAE cursors.

Please feel free to edit this answer with improvements.

0

精彩评论

暂无评论...
验证码 换一张
取 消