Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's meaning of orphans in django's paginator?

I found the /django/core/paginator.py source code:

class Paginator(object):
def __init__(self, object_list, per_page, orphans=0, allow_empty_first_page=True):
    self.object_list = object_list
    self.per_page = int(per_page)
    self.orphans = int(orphans)
    self.allow_empty_first_page = allow_empty_first_page
    self._num_pages = self._count = None

what's the attribute orphans meaning?

like image 252
liuzhijun Avatar asked Sep 07 '13 04:09

liuzhijun


People also ask

What is paginator in django?

Django provides a few classes that help you manage paginated data – that is, data that's split across several pages, with “Previous/Next” links. These classes live in django/core/paginator.py. For examples, see the Pagination topic guide.

What is Page_obj?

Generated a page object called page_obj , which contains the paginated employee data along with metadata for navigating to the previous and next pages.

How does django paginator work?

How does Django pagination work? The Paginator class takes in a queryset (such as a Django model) and splits it into Page objects that are then displayed across these pages while still using the same HTML document.


1 Answers

From the docs

orphans
The minimum number of items allowed on the last page, defaults to zero. Use this when you don’t want to have a last page with very few items. If the last page would normally have a number of items less than or equal to orphans, then those items will be added to the previous page (which becomes the last page) instead of leaving the items on a page by themselves. For example, with 23 items, per_page=10, and orphans=3, there will be two pages; the first page with 10 items and the second (and last) page with 13 items.

like image 187
sberry Avatar answered Oct 05 '22 00:10

sberry