Author: adrian
Date: 2006-06-03 17:06:48 -0500 (Sat, 03 Jun 2006)
New Revision: 3071

Modified:
   django/trunk/django/views/generic/list_detail.py
   django/trunk/docs/generic_views.txt
Log:
Fixed #2075 -- Added 'page' parameter to object_list generic view. Thanks, 
[EMAIL PROTECTED]

Modified: django/trunk/django/views/generic/list_detail.py
===================================================================
--- django/trunk/django/views/generic/list_detail.py    2006-06-03 13:37:34 UTC 
(rev 3070)
+++ django/trunk/django/views/generic/list_detail.py    2006-06-03 22:06:48 UTC 
(rev 3071)
@@ -4,8 +4,8 @@
 from django.core.paginator import ObjectPaginator, InvalidPage
 from django.core.exceptions import ObjectDoesNotExist
 
-def object_list(request, queryset, paginate_by=None, allow_empty=False,
-        template_name=None, template_loader=loader,
+def object_list(request, queryset, paginate_by=None, page=None,
+        allow_empty=False, template_name=None, template_loader=loader,
         extra_context=None, context_processors=None, 
template_object_name='object',
         mimetype=None):
     """
@@ -38,7 +38,8 @@
     queryset = queryset._clone()
     if paginate_by:
         paginator = ObjectPaginator(queryset, paginate_by)
-        page = request.GET.get('page', 1)
+        if not page:
+            page = request.GET.get('page', 1)
         try:
             page = int(page)
             object_list = paginator.get_page(page - 1)

Modified: django/trunk/docs/generic_views.txt
===================================================================
--- django/trunk/docs/generic_views.txt 2006-06-03 13:37:34 UTC (rev 3070)
+++ django/trunk/docs/generic_views.txt 2006-06-03 22:06:48 UTC (rev 3071)
@@ -641,8 +641,10 @@
 
     * ``paginate_by``: An integer specifying how many objects should be
       displayed per page. If this is given, the view will paginate objects with
-      ``paginate_by`` objects per page. The view will expect a ``page`` query
-      string (GET) parameter containing a zero-indexed page number.
+      ``paginate_by`` objects per page. The view will expect either a ``page``
+      query string parameter (via ``GET``) containing a zero-indexed page
+      number, or a ``page`` variable specified in the URLconf. See
+      "Notes on pagination" below.
 
     * ``template_name``: The full name of a template to use in rendering the
       page. This lets you override the default template name (see below).
@@ -711,6 +713,25 @@
     * ``hits``: The total number of objects across *all* pages, not just this
       page.
 
+Notes on pagination
+~~~~~~~~~~~~~~~~~~~
+
+If ``paginate_by`` is specified, Django will paginate the results. You can
+specify the page number in the URL in one of two ways:
+
+    * Use the ``page`` parameter in the URLconf. For example, this is what
+      your URLconf might look like::
+
+        (r'^objects/page(?P<page>[0-9]+)/$', 'object_list', dict(info_dict))
+
+    * Pass the page number via the ``page`` query-string parameter. For
+      example, a URL would look like this:
+
+        /objects/?page=3
+
+In both cases, ``page`` is 1-based, not 0-based, so the first page would be
+represented as page ``1``.
+
 ``django.views.generic.list_detail.object_detail``
 --------------------------------------------------
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---

Reply via email to