Ticket #7005: misc-orphans-fixes-8147.diff
File misc-orphans-fixes-8147.diff, 3.8 KB (added by , 16 years ago) |
---|
-
django/views/generic/list_detail.py
4 4 from django.core.paginator import Paginator, InvalidPage 5 5 from django.core.exceptions import ObjectDoesNotExist 6 6 7 def object_list(request, queryset, paginate_by=None, page=None, 7 def object_list(request, queryset, paginate_by=None, page=None, orphans=None, 8 8 allow_empty=True, template_name=None, template_loader=loader, 9 9 extra_context=None, context_processors=None, template_object_name='object', 10 10 mimetype=None): … … 45 45 if extra_context is None: extra_context = {} 46 46 queryset = queryset._clone() 47 47 if paginate_by: 48 paginator = Paginator(queryset, paginate_by, allow_empty_first_page=allow_empty )48 paginator = Paginator(queryset, paginate_by, allow_empty_first_page=allow_empty, orphans=orphans) 49 49 if not page: 50 50 page = request.GET.get('page', 1) 51 51 try: -
docs/pagination.txt
59 59 ... 60 60 InvalidPage 61 61 62 ################# 63 # Orphan support 64 ################# 65 66 # With orphans=2 and 2 items per page, we get all 4 items on a single page. 67 >>> paginator = Paginator(objects, 2, orphans=2) 68 >>> paginator.num_pages 69 1 70 >>> page = paginator.page(1) 71 >>> page.object_list 72 ['john', 'paul', 'george', 'ringo'] 73 74 # With orphans only set to 1, we get two pages. 75 >>> paginator = Paginator(objects, 2, orphans=1) 76 >>> paginator.num_pages 77 2 78 >>> page = paginator.page(1) 79 >>> page.object_list 80 ['john', 'paul'] 81 >>> page = paginator.page(2) 82 >>> page.object_list 83 ['george', 'ringo'] 84 85 62 86 Note that you can give ``Paginator`` a list/tuple, a Django ``QuerySet``, or 63 87 any other object with a ``count()`` or ``__len__()`` method. When determining 64 88 the number of objects contained in the passed object, ``Paginator`` will first … … 66 90 has no ``count()`` method. This allows objects such as Django's ``QuerySet`` to 67 91 use a more efficient ``count()`` method when available. 68 92 93 ``Paginator`` also accepts an optional argument ``orphans`` which specifies the 94 number of objects that can be included over the specified page limit (when 95 creating a ``Paginator`` instance) in order to preclude a final page which 96 contains only a few objects. For example, if paginating a list of 101 objects 97 by 20 with no orphans, the ``Paginator`` will generate 5 pages with 20 objects 98 each, and a sixth page with a single object. Under the same scenario but with 99 the ``orphans`` argument set to 1 (or greater), the ``Paginator`` will generate 100 4 pages with 20 objects each, and a fifth page with 21 objects. 101 69 102 ``Paginator`` objects 70 103 ===================== 71 104 -
docs/generic_views.txt
704 704 * ``page``: The current (1-based) page number, as an integer, or the string 705 705 ``'last'``. See `Notes on pagination`_ below. 706 706 707 * ``orphans``: The number of extra objects to allow the Paginator to include 708 on the last page. This optionally extends the ``paginate_by`` limit in 709 order to keep the last page from having a very small number of objects. 710 This only has effect when ``paginate_by`` is used. 711 See `Notes on pagination`_ below. 712 707 713 * ``template_name``: The full name of a template to use in rendering the 708 714 page. This lets you override the default template name (see below). 709 715