2

I'm astonished by how little documentation on class-based generic views there is.
Anything slightly more complex than a trivial sample has to get done through guesswork, trial and error.

I want to use WeekArchiveView to display a week's item list.

There's my urls.py entry:

url(r'^items/(?P<year>\d{4})/week/(?P<week>\d{1,2})/$', ItemWeekArchiveView.as_view())

When no year or week is specified, I get an error page.
I want them to equal today's year and week by default.

What is the right place for tweak here? Should I introduce another mixing and override a method?

Dan Abramov
  • 264,556
  • 84
  • 409
  • 511

1 Answers1

3

Urls like /items/ or /items/2011/ wouldn't match your regexp because \d{4} means exactly 4 digits.

You probably should specify two another url entries for both cases:

url(r'^items/$', AchievementListView.as_view(
    year=str(date.today().year), week=str(date.today().isocalendar()[1])
    )),
url(r'^items/(?P<year>\d{4})/week/(?P<week>\d{1,2})/$', ItemWeekArchiveView.as_view()),

(Using isocalendar to get the week number).

Community
  • 1
  • 1
Ivan Ivanov
  • 2,042
  • 1
  • 19
  • 28