【发布时间】:2018-02-10 06:31:33
【问题描述】:
我在 django 1.8 中有一个项目,我想提取 date_start 字段以获取年份,然后创建事件发生年份的范围。然后将其全部传递给SelectDateWidget,格式为:
date_start = forms.DateField(widget=SelectDateWidget(years=range(1980, 2018)))
但我收到了:too many values to unpack (expected 2)
这是我的代码有问题的部分:
context['years'] = models.Booking.objects.filter('date_start')
这是我认为的所有代码:
class BookingListView(ListView, FormView):
model = models.Booking
form_class = BookingForm
queryset = models.Booking.objects.order_by('-date_start')
paginate_by = 80
template_name = 'events/archive_list.html'
context_object_name = 'object_list'
date_field = 'date_start'
allow_future = True
def get_context_data(self, **kwargs):
context = super(BookingListView, self).get_context_data(**kwargs)
context['mode'] = 'archive'
context['form'] = BookingForm()
context['years'] = models.Booking.objects.filter('date_start')
print(context['years'])
return context
【问题讨论】:
-
在问题中包含完整的错误回溯
-
除非您将完整的回溯发布到您的错误,否则没有人能够通过查看 2 行代码和一个与任何行号/函数调用/参数值无关的可能错误字符串来帮助您等
-
请立即查看。
标签: python django date filter django-queryset