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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access