title: Django Generic Views: When to use ListView vs. DetailView
body: <p>I am using Django's class based generic views in a blog application. One of my views displays a list of posts that have a certain tag. I can write this view as a <code>ListView</code> of posts, filtered by tag. Or I can write this view as a <code>DetailView</code> of the tag, and add the relevant posts to the context.</p>
  
  <p>Is one way more proper -- or Pythonic -- than the other?</p>
  
  <p>The <code>ListView</code> approach seems more semantic, because what I want is a <em>list</em> of posts, but it's also slightly more complex. It requires that I overwrite two methods. The <code>DetailView</code> approach only requires me to overwrite one method.</p>
  
  <pre><code>class PostTagView(ListView):
      """Display all blog posts with a given tag."""
      queryset = Post.objects.published()
  
      def get_context_data(self, **kwargs):
          context = super(PostTagView, self).get_context_data(**kwargs)
          context['tag'] = get_object_or_404(Tag, slug=self.kwargs['slug'])
          return context
  
      def get_queryset(self, **kwargs):
          queryset = super(PostTagView, self).get_queryset()
          return queryset.filter(tags__slug=self.kwargs['slug'])
  
  
  class TagDetailView(DetailView):
      """Display all blog posts with a given tag."""
      model = Tag
  
      def get_context_data(self, **kwargs):
          context = super(TagDetailView, self).get_context_data(**kwargs)
          context['object_list'] = Post.objects.published().filter(tags__slug=self.kwargs['slug'])
          return context
  </code></pre>