title: Django QuerySet: Why can't I filter an annotated QuerySet?
body: <p>I'm trying to retrieve a list of the 100 most popular books in my db, and then create a list of unique categories that are in that list. Here are my simplified Book, Favorite, and Category models:</p>
  
  <pre><code>class Book(models.Model):
      name = models.CharField(max_length=100)
      category = models.ForeignKey(Category)
  
  class Favorite(models.Model):
      user = models.ForeignKey(User)
      book = models.ForeignKey(Book)
  
  class Category(models.Model):
      name = models.CharField(max_length=100)
  </code></pre>
  
  <p>I can easily get a list of the 100 most popular books using the following query:</p>
  
  <pre><code>books =  Book.objects.annotate(num_favorites=Count('favorite')).order_by('-num_favorites')[:100]
  </code></pre>
  
  <p>But where I start having problems is when I try to get a list of unique categories for those 100 most popular books. The following query does not work (error posted below) and I can't seem to figure out why.</p>
  
  <pre><code>&gt;&gt;&gt; categories = Category.objects.filter(book__in=books).distinct()
  &gt;&gt;&gt; categories
  
  
  FieldError: Cannot resolve keyword 'num_favorites' into field. Choices are: category, favorite, id, name
  </code></pre>
  
  <p>Can anyone shed some light on what I'm missing here?</p>