#20659: Error in the example for Using SingleObjectMixin with ListView
--------------------------------+--------------------
     Reporter:  tudor.prodan@…  |      Owner:  nobody
         Type:  Uncategorized   |     Status:  new
    Component:  Documentation   |    Version:  1.5
     Severity:  Normal          |   Keywords:
 Triage Stage:  Unreviewed      |  Has patch:  0
Easy pickings:  1               |      UI/UX:  0
--------------------------------+--------------------
 In this section:
 https://docs.djangoproject.com/en/1.5/topics/class-based-views/mixins
 /#using-singleobjectmixin-with-listview

 The example code has a mistake.

 Both `SingleObjectMixin.get_object` and `ListView` will use
 `self.get_queryset`.
 `get_queryset` is overwritten in the example to always return `book_set`,
 hence, `get_object` will always fail.

 `get_object` does take an optional `queryset` parameter, which, if passed,
 will be used instead of `self.get_queryset`, so the example may work if
 when calling `get_object`:

 {{{
     def get(self, request, *args, **kwargs):
 -        self.object = self.get_object()
 +        self.object = self.get_object(queryset=self.model.objects)
         return super(PublisherDetail, self).get(request, *args, **kwargs)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20659>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.48e876a297b4142b17a96e82e2247a8d%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to