In continuation of my struggle with WeekArchiveView
, how do I paginate it by week?
All I want is:
- to know if there is next / previous week available;
- in case there is, provide a link in the template.
I'd like it to also skip empty weeks.
The source shows get_next_day
/ get_prev_day
and get_next_month
/ get_prev_month
are available, but nothing for weeks.
Taking chrisdpratt's code as basis, I created a class that provides the template with
next_week
andprevious_week
:This works perfect.
That is definitely interesting. Sure enough
MonthMixin
includesget_next_month
/get_prev_month
methods, andDayMixin
includesget_next_day
/get_prev_day
methods. However, both YearMixin and WeekMixin have no functional equivalent in their definitions. Seems like a bit of an oversight on the Django team's part.I think your best bet is to subclass either WeekArchiveView or BaseWeekArchiveView (if you may eventually want to change up the response format and don't want to have to re-implement your methods) and add your own
get_next_week
/get_prev_week
methods. Then have your view inherit from your subclass instead. A simple modification ofDayMixin
s methods should be sufficient.