title: Django Query too slow because of for()
body: <p>Suppose context['cat'] is a list which can have several values ['X', 'Y', 'Z'] and 'category' field can also have several values:  ['X'] or ['X,Y'].</p>
  
  <p><strong>This code</strong> lets me obtain all the objects that I want. The <strong>problem</strong> is that I have 4 million records. When I tried this code on 100k records there was no delay, but with 4M records there is a 20secs delay.</p>
  
  <pre><code>paper_list = model1.objects.filter(reduce(operator.or_, (Q(category__icontains=x) for x in context['cat'])))
  </code></pre>
  
  <p>I have been told that the solution may be to use ManyToMany relations on the models but that is something that I don't know how to use even though I read the documentation <a href="https://docs.djangoproject.com/es/1.9/topics/db/examples/many_to_many/" rel="nofollow">ManyToMany</a>.</p>
  
  <p>Is there a way of making this possible without that structure? I wanted to use something like the LIKE expression on MySQL, but 'icontains' isn't giving me what I want unless I use a for(), which has delays with so many records.</p>
  
  <p>In case it is of any help, this is the model I loaded all the records onto, and I don't have more records:</p>
  
  <pre><code>class model1(models.Model): 
     author= models.CharField(max_length=200, blank=True)
     title= models.CharField(max_length=200, blank=True)
     sum= models.CharField(max_length=200, blank=True)
     key= models.CharField(max_length=200, blank=True)
     iso= models.CharField(max_length=200, blank=True)
     extra= models.CharField(max_length=200, blank=True)
     url= models.CharField(max_length=200, blank=True)
     category= models.CharField(db_index=True, max_length=199)
  </code></pre>
  
  <p>Could someone point me in the right direction?</p>