title: How to use Q objects in Django
body: <p>I am trying to understand how to make a simple search form for a website in Django. After some google search and few failures to do it on my own I ended up with the following code in views.py where 'q' is value retrieved from the form: </p>
  
  <pre><code>class BookSearchListView(BookListView):
      def get_queryset(self):
          result=super(BookSearchListView, self).get_queryset()
          query=self.request.GET.get('q')
          if query:
              query_list=query.split()
              result=result.filter(reduce(operator.and_,(Q(title__icontains=q) for q in query_list))) 
          return result
  </code></pre>
  
  <p>I already understand how it works and why there is reduce and operator.and_ (I mean, I think I understand). But I do not understand why a simple  <code>result=result.filter(Q(somedbfield_icontains=q))</code> returns and error (even if input is a single word). I also don't understand why reduce needs to get bitwise value? </p>