我正在尝试让 weekarchive 视图正常工作,但出现以下错误:
NameError at /archive/week/2012/48/
global name '_get_next_prev_month' is not defined
Request Method: GET
Request URL: http://localhost:8000/archive/week/2012/48/
Django Version: 1.4.2
Exception Type: NameError
Exception Value:
global name '_get_next_prev_month' is not defined
Exception Location: /job/views.py in get_next_week, line 79
Python Executable: /jobenv/bin/python
Python Version: 2.7.3
这是我的视图继承自的子类:
class BetterWeekArchiveView(WeekArchiveView):
def get_next_week(self, date):
"""
Get the next valid week.
"""
from datetime import timedelta
next = date + timedelta(days=7)
return _get_next_prev_month(self, next, is_previous=False, use_first_day=False)
def get_previous_week(self, date):
"""
Get the previous valid week.
"""
from datetime import timedelta
prev = date - timedelta(days=7)
return _get_next_prev_month(self, prev, is_previous=True, use_first_day=False)
def get_dated_items(self):
"""
Return (date_list, items, extra_context) for this request.
Inject next_week and previous_week into extra_context.
"""
result = super(BetterWeekArchiveView, self).get_dated_items()
extra_context = result[2]
date = extra_context['week']
extra_context.update({
'next_week': self.get_next_week(date),
'previous_week': self.get_previous_week(date),
})
return result
这是视图:
class week_archive(BetterWeekArchiveView):
model=Job
allow_future =True
allow_empty=True
paginate_by=12
date_field='datemade'
template_name='task/task_archive_week'
def get_queryset(self):
return Job.objects.filter(author=self.request.user)
我从如何对 WeekArchiveView 进行分页得到了这个 BetterWeekArchiveView()
我做错了什么?