Answer the question
In order to leave comments, you need to log in
How to organize the search form according to different models?
There are two models and a search form. There are two fields in the form: 1 - search phrase, 2 - select by which you select which model to search for. From the getom form I pass these fields to the view:
class ShortSearchView(AllPagesMixin, ListView):
'''Результаты быстрого поиска'''
context_object_name = 'result_list'
template_name = 'main/search_list.html'
paginate_by = 20
def get_queryset(self):
where = self.request.GET.get('where', '')
word = self.request.GET.get('word', '')
if where == '1':
result = First.objects.filter(name__icontains=word)
elif where == '2':
result = Second.objects.filter(name__icontains=word)
else:
result = False
return result
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question