Answer the question
In order to leave comments, you need to log in
How to filter by multiple parameters?
Hi, how to filter by multiple parameters in Django? For example, I want to display 2-3 categories or 3-4 tags at the same time?
For example, I display one category like this
url(r'^category/(?P<id>\d+)$', views.blog_category, name='category'),
Answer the question
In order to leave comments, you need to log in
Well, for example like this:
url(r'^category/(?P<pk1>\d+)/(?P<pk2>\d+)/(?P<pk3>\d+)/$', views.index, name='category'),
class Index(generic.ListView):
model = Category
paginate_by = 3
ordering = '-id'
template_name = 'articles/index.html'
def get_queryset(self):
return Category.objects.filter(id__in=(self.kwargs('pk1'), self.kwargs('pk2'), self.kwargs('pk3')))
index = Index.as_view()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question