1

如何将通用视图中的请求变量传递给查询集。

例如,我需要将请求中的req_brand_slug传递给查询集中的过滤器:

all_by_brand = {
    'queryset': Br.objects.filter(slug=req_brand_slug)
}
url(r'^model/(?P<req_brand_slug>[\w|-]+)/$', all_by_brand , name='brand'), 
4

1 回答 1

3

您必须创建自己的视图,该视图使用自定义参数调用通用视图。

from django.views.generic.list_detail import object_list

def my_view(request, req_brand_slug):
    extra_context = {}
    return object_list(request, queryset=Br.objects.filter(slug=req_brand_slug),
                       template_name="my_template.html",
                       paginate_by=20,
                       extra_context=extra_context)
于 2011-02-28T12:22:43.907 回答