django list view template 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: class based detail view year permalink
from django.shortcuts import get_object_or_404
class MagDetail(DetailView):
model = Mag
def get_object(self):
obj = get_object_or_404(
self.model,
pk=self.kwargs['pk'],
pub_date__year=self.kwargs['year'])
return obj