errx
errx

Reputation: 1791

generic views: object_list how to pass request variable

How to pass request variable in generic views to a queryset.

For example i need to pass req_brand_slug from request to a filter in queryset:

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

Upvotes: 1

Views: 876

Answers (1)

Botond B&#233;res
Botond B&#233;res

Reputation: 16673

You'll have to create your own view which calls the generic view with custom params.

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)

Upvotes: 3

Related Questions