17.7.3 Creating ArchiveIndexView

Ideally, we want to link to our new PostArchiveYear webpage from the PostList page. To do so, we need a list of all of the dates our Post objects have been published. We could add the result of Post.object.dates('pub_date', 'year') to our template context, modify post_list.html, and call it a day. Instead (and despite the fact that this section is about adding GCBV), we will replace ListView with ArchiveIndexView as PostList’s superclass.

Much like PostList, ArchiveIndexView shows a list of objects. Both may be paginated (a feature we have yet to use on a GCBV). However, ArchiveIndexView is meant to be integrated with MonthArchiveView and YearArchiveView and expects the DateField (or DateTimeField) to work properly. ...

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.