title: How to count number of entries, annotate it and select latest with Django ORM
body: <p>I need to select entries which match specific pattern, count them and the pick latest. How to do this via Django ORM?</p>
  
  <p>Tried:</p>
  
  <pre><code>Entry.objects.filter(A=B).annotate(Count("something")).latest("date")
  </code></pre>
  
  <p>This counts only 1 item for each B. If I remove <code>latest("date")</code>, it counts correctly but gives only count number and nothing else. How to perform this task correctly?</p>
  
  <p><strong>UPD:</strong> Actual code</p>
  
  <pre><code>def render_entries(request):
      ids = Entry.objects.values("entry_token").distinct()
      entries = [Entry.objects.filter(entry_token=x["entry_token"]).annotate(count=Count("id")).latest("date_time") for x in ids]
      return render(request, "entries_list.html", {'entries':entries})
  </code></pre>