C
C
Cyber_bober2016-03-09 10:35:56
Django
Cyber_bober, 2016-03-09 10:35:56

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'),

tags, similar. How to make a multiple selection at the url level and request formation, please tell me?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Voronkov, 2016-03-09
@Cyber_bober

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 question

Ask a Question

731 491 924 answers to any question