title: Subquery many-to-many relation in Django 1.9
body: <p>I have such models:</p>
  
  <pre><code>class Genre(models.Model):
      name = models.TextField(null=True, blank=True)
      min_age = models.IntegerField(default=0)
      max_age = models.IntegerField(default=0)
      objects = GenreManager()
  
      class Meta:
          get_latest_by = 'id'
  
  
  class Book(models.Model):
      name = models.TextField(null=True, blank=True)
      genres = models.ManyToManyField(Genre, related_name='genres')
      suggested_age = models.IntegerField(default=0)
      objects = BookManager()
  </code></pre>
  
  <p>and I want to query it in such way: there can be duplicates (when min/max age changes, new object will be saved to db), but I want to get the latest one, so I come up with:</p>
  
  <pre><code>class GenreManager(models.Manager):
      def get_latest_genre_obj(self, genre):
          return self.get_queryset().filter(name=genre).latest()
  </code></pre>
  
  <p>to be able to retrieve one. Now, I want to get books, using <code>Genre</code> object from above - I need min and max age values in my query. I've tried something like this:</p>
  
  <pre><code>class BookManager(models.Manager):
      def get_books_from_genre(self, genre):
          genre = Genre.objects.get_latest_genre_obj(genre)
          return self.get_queryset().annotate(actual_genre=genre).filter(actual_genre__min_age__gte=F('suggested_age'), actual_genre__max_age__lte=F('suggested_age'))
  </code></pre>
  
  <p>But it looks like I cannot annotate object to other object:</p>
  
  <pre><code>AttributeError: 'Genre' object has no attribute 'resolve_expression'
  </code></pre>
  
  <p>So, how to query it like I want to? I thought about <code>Subquery()</code> as I thought it can help me, but it's Django 1.11 feature andI'm using 1.9 version. To sum up what I want to achieve: from genres, retrieve newest (with highest <code>id</code>) object with particular name and use it's fields while querying for books - so I need to have access to it's fields.</p>