title: Django: ManyToMany filter matching on ALL items in a list
body: <p>I have such a Book model:</p>
  
  <pre><code>class Book(models.Model):
      authors = models.ManyToManyField(Author, ...)
      ...
  </code></pre>
  
  <p>In short: </p>
  
  <p>I'd like to retrieve the books whose authors are strictly equal to a given set of authors. I'm not sure if there is a single query that does it, but any suggestions will be helpful.</p>
  
  <p>In long:</p>
  
  <p>Here is what I tried, (that failed to run getting an AttributeError)</p>
  
  <pre><code># A sample set of authors
  target_authors = set((author_1, author_2))
  
  # To reduce the search space, 
  # first retrieve those books with just 2 authors.
  candidate_books = Book.objects.annotate(c=Count('authors')).filter(c=len(target_authors))
  
  final_books = QuerySet()
  for author in target_authors:
      temp_books = candidate_books.filter(authors__in=[author])
      final_books = final_books and temp_books
  </code></pre>
  
  <p>... and here is what I got:</p>
  
  <pre><code>AttributeError: 'NoneType' object has no attribute '_meta'
  </code></pre>
  
  <p>In general, how should I query a model with the constraint that its ManyToMany field contains a set of given objects as in my case?</p>
  
  <p>ps: I found some relevant SO questions but couldn't get a clear answer. Any good pointer will be helpful as well. Thanks.</p>