detail view django code example
Example 1: django listview
class YourView(ListView):
model = YourModel
paginate_by = your_pagination_number
context_object_name = 'your_model_in_plural'
template_name = 'your_list.html'
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
Example 3: django detailview
class YourView(DetailView):
model = YourModel
template_name = 'your_template.html'