summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2013-07-01 14:05:49 +0200
committerBaptiste Mispelon <bmispelon@gmail.com>2013-07-01 14:05:49 +0200
commit88de53d4a86548016f245a1413b856aa334bc737 (patch)
tree19cb92090c47c7708063e5e3d7a0accad392f44e /docs
parentd5589b4cd3238c4bf4063ddd8239d22b37caa7d3 (diff)
Fixed #20659 -- Fixed PublisherDetail in CBV topic documentation.
Thanks to tudor.prodan, susan, and Tim Graham for the report and reviews.
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/class-based-views/mixins.txt25
1 files changed, 12 insertions, 13 deletions
diff --git a/docs/topics/class-based-views/mixins.txt b/docs/topics/class-based-views/mixins.txt
index 84d7417233..df1a5505a5 100644
--- a/docs/topics/class-based-views/mixins.txt
+++ b/docs/topics/class-based-views/mixins.txt
@@ -286,18 +286,18 @@ One way to do this is to combine :class:`ListView` with
for the paginated list of books can hang off the publisher found as the single
object. In order to do this, we need to have two different querysets:
-``Publisher`` queryset for use in
- :meth:`~django.views.generic.detail.SingleObjectMixin.get_object()`
- We'll set the ``model`` attribute on the view and rely on the default
- implementation of ``get_object()`` to fetch the correct ``Publisher``
- object.
-
``Book`` queryset for use by :class:`~django.views.generic.list.ListView`
- The default implementation of ``get_queryset()`` uses the ``model`` attribute
- to construct the queryset. This conflicts with our use of this attribute
- for ``get_object()`` so we'll override that method and have it return
- the queryset of ``Book`` objects linked to the ``Publisher`` we're looking
- at.
+ Since we have access to the ``Publisher`` whose books we want to list, we
+ simply override ``get_queryset()`` and use the ``Publisher``'s
+ :ref:`reverse foreign key manager<backwards-related-objects>`.
+
+``Publisher`` queryset for use in :meth:`~django.views.generic.detail.SingleObjectMixin.get_object()`
+ We'll rely on the default implementation of ``get_object()`` to fetch the
+ correct ``Publisher`` object.
+ However, we need to explicitly pass a ``queryset`` argument because
+ otherwise the default implementation of ``get_object()`` would call
+ ``get_queryset()`` which we have overridden to return ``Book`` objects
+ instead of ``Publisher`` ones.
.. note::
@@ -317,12 +317,11 @@ Now we can write a new ``PublisherDetail``::
from books.models import Publisher
class PublisherDetail(SingleObjectMixin, ListView):
- model = Publisher # for SingleObjectMixin.get_object
paginate_by = 2
template_name = "books/publisher_detail.html"
def get(self, request, *args, **kwargs):
- self.object = self.get_object()
+ self.object = self.get_object(queryset=Publisher.objects.all())
return super(PublisherDetail, self).get(request, *args, **kwargs)
def get_context_data(self, **kwargs):