title: Django - Filter a queryset by Max(date) year
body: <p>I would like to know if I can get in a single query, All the objects of certain model where its date's year equals the year of the Max('date') of the model. For example, using the models from the <a href="https://docs.djangoproject.com/en/dev/topics/db/aggregation/" rel="noreferrer">Aggregation Django Docs</a>, how can I get All the <code>Book</code>s published in the year of the more recently published <code>Book</code>?</p>
  <p>All the examples in the docs filter by immediate values (<code>pubdate__year=2006</code>), but I need to use a calculated value over the same object in the same query.</p>
  <p>Of course, I could do this by performing two queries: one for getting the max year, and a second one to filter by that year, but I think it should be possible to do it in a single query. It's just I haven't figured it out yet.</p>
  <p>Thanks for your help!</p>
  <h2>EDIT:</h2>
  <p>Since some of you have given similar answers, I'm writing this update so my problem can be better understood.</p>
  <p>This is my model:</p>
  <pre><code>class Expo(models.Model):
  
      class Meta:
          verbose_name= _('Expo')
          verbose_name_plural = _('Expos')
  
      name = models.CharField(max_length=255)
      place = models.CharField(max_length=255, null=True, blank=True)
      date = models.DateField()
      bio = models.ForeignKey(Bio, related_name='expos')
  </code></pre>
  <p>I need <strong>&quot;All the <code>Expo</code>s that happened in the latest year of the list of <code>Expo</code>s stored in my database&quot;</strong></p>
  <p>To resolve this, I'm doing this:</p>
  <pre><code>from django.db.models import Max
  max_year = Expo.objects.all().aggregate(Max('date'))['date__max'].year
  expos = Expo.objects.filter(date__year=max_year)
  </code></pre>
  <p>But this, I understand that performs two queries on the database. I would like an expression  that let me get the same result, but performing a single query.</p>
  <p>I've tried as suggested:</p>
  <pre><code>Expo.objects.annotate(max_year=Max('date__year')).filter(date__year=F('max_year'))
  </code></pre>
  <p>But get the error:</p>
  <pre><code>FieldError: Join on field 'date' not permitted. Did you misspell 'year' for the lookup type?
  </code></pre>
  <p>I also have tried:</p>
  <pre><code>Expo.objects.annotate(max_date=Max('date')).filter(date__year__gte=F('max_date__year'))
  </code></pre>
  <p>but I get the error:</p>
  <pre><code>FieldError: Cannot resolve keyword 'max_date' into field. Choices are: bio, date, id, items, name, place, max_date
  </code></pre>
  <p>Notice that it says that it can't resolve <code>'max_date'</code>, but it appears listed among the choices. Weird.</p>
  <p>Again, Thanks a lot for your help! :)</p>