[英]How to send 2 query sets in a django CBV(ListView)
class myView(ListView):
template_name = "myView.html"
def get_context_data(**kwargs):
queryset = people.objects.all()
queryset2 = people.objects.filter(stage = 4)
context = {
'paginator': None,
'page_obj': None,
'is_paginated': False,
'object_list_all': queryset,
'object_list_4': queryset2
}
context.update(kwargs)
return context
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(myView, self).dispatch(*args, **kwargs)
` `
I am getting the following error: myView
must define queryset
or model
. 我收到以下错误: myView
必须定义queryset
或model
。 What should I do to fix this? 我应该怎么做才能解决这个问题?
There doesn't seem to be any reason to make this a ListView. 似乎没有任何理由使它成为ListView。 The only thing a ListView does is generate an object_list context item from the model or queryset attributes. ListView唯一要做的就是从model或queryset属性生成一个object_list上下文项。 If you don't want that, just make it a standard TemplateView. 如果您不想这样做,只需将其设为标准TemplateView。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.