Opened 5 years ago

Last modified 5 years ago

#30699 closed Cleanup/optimization

Remove `PublisherDetail.get_context_data()` from documentation — at Version 1

Reported by: Davit Gachechiladze Owned by: Davit Gachechiladze
Component: Documentation Version: 2.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Davit Gachechiladze)

The following code snippet is from https://docs.djangoproject.com/en/2.2/topics/class-based-views/mixins/

from django.views.generic import ListView
from django.views.generic.detail import SingleObjectMixin
from books.models import Publisher

class PublisherDetail(SingleObjectMixin, ListView):
    paginate_by = 2
    template_name = "books/publisher_detail.html"

    def get(self, request, *args, **kwargs):
        self.object = self.get_object(queryset=Publisher.objects.all())
        return super().get(request, *args, **kwargs)

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['publisher'] = self.object
        return context

    def get_queryset(self):
        return self.object.book_set.all()

PublisherDetail.get_context_data(self, **kwargs) is not neccessary here at all, isn't it ? SingleObjectMixin.get_context_data(self, **kwargs) is responsible to add publisher key in context dict, which is called from BaseListView.get(self, request, *args, **kwargs).

https://github.com/django/django/pull/11658

Change History (1)

comment:1 by Davit Gachechiladze, 5 years ago

Description: modified (diff)
Owner: changed from nobody to Davit Gachechiladze
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top