Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2075 -- Added 'page' parameter to object_list generic view. Th…

…anks, kanashii@kanashii.ca

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3071 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit fc2a02f9666a2cd610443fc2107560b9832a017a 1 parent 9b86db9
Adrian Holovaty authored June 03, 2006
7  django/views/generic/list_detail.py
@@ -4,8 +4,8 @@
4 4
 from django.core.paginator import ObjectPaginator, InvalidPage
5 5
 from django.core.exceptions import ObjectDoesNotExist
6 6
 
7  
-def object_list(request, queryset, paginate_by=None, allow_empty=False,
8  
-        template_name=None, template_loader=loader,
  7
+def object_list(request, queryset, paginate_by=None, page=None,
  8
+        allow_empty=False, template_name=None, template_loader=loader,
9 9
         extra_context=None, context_processors=None, template_object_name='object',
10 10
         mimetype=None):
11 11
     """
@@ -38,7 +38,8 @@ def object_list(request, queryset, paginate_by=None, allow_empty=False,
38 38
     queryset = queryset._clone()
39 39
     if paginate_by:
40 40
         paginator = ObjectPaginator(queryset, paginate_by)
41  
-        page = request.GET.get('page', 1)
  41
+        if not page:
  42
+            page = request.GET.get('page', 1)
42 43
         try:
43 44
             page = int(page)
44 45
             object_list = paginator.get_page(page - 1)
25  docs/generic_views.txt
@@ -641,8 +641,10 @@ A page representing a list of objects.
641 641
 
642 642
     * ``paginate_by``: An integer specifying how many objects should be
643 643
       displayed per page. If this is given, the view will paginate objects with
644  
-      ``paginate_by`` objects per page. The view will expect a ``page`` query
645  
-      string (GET) parameter containing a zero-indexed page number.
  644
+      ``paginate_by`` objects per page. The view will expect either a ``page``
  645
+      query string parameter (via ``GET``) containing a zero-indexed page
  646
+      number, or a ``page`` variable specified in the URLconf. See
  647
+      "Notes on pagination" below.
646 648
 
647 649
     * ``template_name``: The full name of a template to use in rendering the
648 650
       page. This lets you override the default template name (see below).
@@ -711,6 +713,25 @@ If the results are paginated, the context will contain these extra variables:
711 713
     * ``hits``: The total number of objects across *all* pages, not just this
712 714
       page.
713 715
 
  716
+Notes on pagination
  717
+~~~~~~~~~~~~~~~~~~~
  718
+
  719
+If ``paginate_by`` is specified, Django will paginate the results. You can
  720
+specify the page number in the URL in one of two ways:
  721
+
  722
+    * Use the ``page`` parameter in the URLconf. For example, this is what
  723
+      your URLconf might look like::
  724
+
  725
+        (r'^objects/page(?P<page>[0-9]+)/$', 'object_list', dict(info_dict))
  726
+
  727
+    * Pass the page number via the ``page`` query-string parameter. For
  728
+      example, a URL would look like this:
  729
+
  730
+        /objects/?page=3
  731
+
  732
+In both cases, ``page`` is 1-based, not 0-based, so the first page would be
  733
+represented as page ``1``.
  734
+
714 735
 ``django.views.generic.list_detail.object_detail``
715 736
 --------------------------------------------------
716 737
 

0 notes on commit fc2a02f

Please sign in to comment.
Something went wrong with that request. Please try again.