queryset django template class based views code example
Example 1: set the context data in django listview
from django.views.generic import DetailView
from books.models import Publisher
class PublisherDetail(DetailView):
context_object_name = 'publisher'
queryset = Publisher.objects.all()
Example 2: get context data django
class PublisherDetail(DetailView):
model = Publisher
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['book_list'] = Book.objects.all()
return context