title: search multiple fields django
body: <p>I'm trying to build a search system, and I want to search by multiple fieldsname, state, city, in my django models. I wrote the below code, yet I've been unable to figure out how to go about it. I use Q but it seems not working:</p>
  
  <p>views.py:</p>
  
  <pre><code>def data_consulting(request):
      if request.method == 'POST':
            form = FilterForm(request.POST)
            if form.is_valid():
                  conditions = [('toBuy', form.cleaned_data['toBuy']), ('name__contains', form.cleaned_data['searchName']),(('price__gte', form.cleaned_data['searchPriceBegin']), ('price__lte',form.cleaned_data['searchPriceEnd'])),(('calories__gte', form.cleaned_data['searchCalorieBegin']), ('calories__lte', form.cleaned_data['searchCalorieEnd'])), (('date__gte',form.cleaned_data['DateBegin']), ('date__lte', form.cleaned_data['DateEnd']))]
                  all_products = Product.objects.filter(reduce(operator.or_, [Q(condition) for condition in conditions]))
                  send = True
                  all_products = Product.objects.filter(reduce(operator.or_, [Q(condition) for condition in conditions]))
             else:
                  form = FilterForm()
                  all_products = Product.objects.all()
      return render(request, 'mealManager/data_consulting.html', locals())
  </code></pre>