[Answer]-Django WeekArchiveView: Have urls start at 1

1👍

The views use strptime to convert a string constructed from the appropriate elements into a Python date, and strptime‘s week parsing uses 0 to represent days that fall before the first start of the week day (Sunday or Monday depending on whether you’re using %U or %W) in a given year. To get Jan 1, 2003 from a week string, you have to give it '0'. So I don’t think there will be a totally simple way to do this.

These are untested, and I wouldn’t really recommend them, but you might be able to customize your get_dated_items method on your view to use something other than strptime to construct the actual date ranges to be covered by the view. Or – and this is pretty ugly – customize get_week to check self.year to see if its first day falls on the week start date, and if not to return a string containing the captured week number minus one.

In both cases you’d have to pay attention to how you generate your URLs as well. What’s currently generating /2013/week/0?

Leave a comment