18.5 Re-creating PostDetail with DateDetailView

In Chapter 17, we used DetailView to replace the behavior of displaying an object in TagDetail and StartupDetail, but we left post_detail() alone. DetailView works only with URL patterns that use a pk, a slug, or both (starting in Django 1.8). Given that our detail page for Post uses the year, month, and slug of the object for uniqueness, it didn’t make any sense to use TagDetail.

Django provides a GCBV called DateDetailView to work with objects that have uniqueness according to a DateField, much in the spirit of ArchiveIndexView or YearArchiveView. The catch is that the GCBV anticipates using the full date: the year, month, and day (on top of the slug). In this section, we not only switch to using ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.