Tweaks to paginator documentation.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16248 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
30e5d7e85e
commit
bce125e84f
|
@ -62,8 +62,8 @@ page::
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
Note that you can give ``Paginator`` a list/tuple, a Django ``QuerySet``, or
|
Note that you can give ``Paginator`` a list/tuple, a Django ``QuerySet``,
|
||||||
any other object with a ``count()`` or ``__len__()`` method. When
|
or any other object with a ``count()`` or ``__len__()`` method. When
|
||||||
determining the number of objects contained in the passed object,
|
determining the number of objects contained in the passed object,
|
||||||
``Paginator`` will first try calling ``count()``, then fallback to using
|
``Paginator`` will first try calling ``count()``, then fallback to using
|
||||||
``len()`` if the passed object has no ``count()`` method. This allows
|
``len()`` if the passed object has no ``count()`` method. This allows
|
||||||
|
@ -185,9 +185,9 @@ Attributes
|
||||||
When determining the number of objects contained in ``object_list``,
|
When determining the number of objects contained in ``object_list``,
|
||||||
``Paginator`` will first try calling ``object_list.count()``. If
|
``Paginator`` will first try calling ``object_list.count()``. If
|
||||||
``object_list`` has no ``count()`` method, then ``Paginator`` will
|
``object_list`` has no ``count()`` method, then ``Paginator`` will
|
||||||
fallback to using ``object_list.__len__()``. This allows objects, such
|
fallback to using ``len(object_list)``. This allows objects, such as
|
||||||
as Django's ``QuerySet``, to use a more efficient ``count()`` method
|
Django's ``QuerySet``, to use a more efficient ``count()`` method when
|
||||||
when available.
|
available.
|
||||||
|
|
||||||
.. attribute:: Paginator.num_pages
|
.. attribute:: Paginator.num_pages
|
||||||
|
|
||||||
|
@ -201,30 +201,37 @@ Attributes
|
||||||
``InvalidPage`` exceptions
|
``InvalidPage`` exceptions
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
The ``page()`` method raises ``InvalidPage`` if the requested page is invalid
|
.. exception:: InvalidPage
|
||||||
(i.e., not an integer) or contains no objects. Generally, it's enough to trap
|
|
||||||
the ``InvalidPage`` exception, but if you'd like more granularity, you can trap
|
A base class for exceptions raised when a paginator is passed an invalid
|
||||||
either of the following exceptions:
|
page number.
|
||||||
|
|
||||||
|
The :meth:`Paginator.page` method raises an exception if the requested page is
|
||||||
|
invalid (i.e., not an integer) or contains no objects. Generally, it's enough
|
||||||
|
to trap the ``InvalidPage`` exception, but if you'd like more granularity, you
|
||||||
|
can trap either of the following exceptions:
|
||||||
|
|
||||||
|
.. exception:: PageNotAnInteger
|
||||||
|
|
||||||
``PageNotAnInteger``
|
|
||||||
Raised when ``page()`` is given a value that isn't an integer.
|
Raised when ``page()`` is given a value that isn't an integer.
|
||||||
|
|
||||||
``EmptyPage``
|
.. exception:: EmptyPage
|
||||||
|
|
||||||
Raised when ``page()`` is given a valid value but no objects exist on that
|
Raised when ``page()`` is given a valid value but no objects exist on that
|
||||||
page.
|
page.
|
||||||
|
|
||||||
Both of the exceptions are subclasses of ``InvalidPage``, so you can handle
|
Both of the exceptions are subclasses of :exc:`InvalidPage`, so you can handle
|
||||||
them both with a simple ``except InvalidPage``.
|
them both with a simple ``except InvalidPage``.
|
||||||
|
|
||||||
|
|
||||||
``Page`` objects
|
``Page`` objects
|
||||||
================
|
================
|
||||||
|
|
||||||
.. class:: Page(object_list, number, paginator)
|
You usually won't construct ``Page`` objects by hand -- you'll get them
|
||||||
|
|
||||||
You usually won't construct :class:`Pages <Page>` by hand -- you'll get them
|
|
||||||
using :meth:`Paginator.page`.
|
using :meth:`Paginator.page`.
|
||||||
|
|
||||||
|
.. class:: Page(object_list, number, paginator)
|
||||||
|
|
||||||
.. versionadded:: 1.4
|
.. versionadded:: 1.4
|
||||||
A page acts like a sequence of :attr:`Page.object_list` when using
|
A page acts like a sequence of :attr:`Page.object_list` when using
|
||||||
``len()`` or iterating it directly.
|
``len()`` or iterating it directly.
|
||||||
|
@ -258,15 +265,15 @@ Methods
|
||||||
|
|
||||||
Returns the 1-based index of the first object on the page, relative to all
|
Returns the 1-based index of the first object on the page, relative to all
|
||||||
of the objects in the paginator's list. For example, when paginating a list
|
of the objects in the paginator's list. For example, when paginating a list
|
||||||
of 5 objects with 2 objects per page, the second page's :meth:`~Page.start_index`
|
of 5 objects with 2 objects per page, the second page's
|
||||||
would return ``3``.
|
:meth:`~Page.start_index` would return ``3``.
|
||||||
|
|
||||||
.. method:: Page.end_index()
|
.. method:: Page.end_index()
|
||||||
|
|
||||||
Returns the 1-based index of the last object on the page, relative to all of
|
Returns the 1-based index of the last object on the page, relative to all
|
||||||
the objects in the paginator's list. For example, when paginating a list of
|
of the objects in the paginator's list. For example, when paginating a list
|
||||||
5 objects with 2 objects per page, the second page's :meth:`~Page.end_index`
|
of 5 objects with 2 objects per page, the second page's
|
||||||
would return ``4``.
|
:meth:`~Page.end_index` would return ``4``.
|
||||||
|
|
||||||
Attributes
|
Attributes
|
||||||
----------
|
----------
|
||||||
|
@ -282,4 +289,3 @@ Attributes
|
||||||
.. attribute:: Page.paginator
|
.. attribute:: Page.paginator
|
||||||
|
|
||||||
The associated :class:`Paginator` object.
|
The associated :class:`Paginator` object.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue