title: Django - Retrieve unique rows by latest date/column
body: <p>I have the following table:</p>
  
  <pre><code>class AccountData(models.Model):
      id = models.BigIntegerField(primary_key=True)
      date = models.DateField()
      last_update = models.DateTimeField()
      account = models.ForeignKey('Account', models.DO_NOTHING, db_column='account', related_name="values")
      value = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
  </code></pre>
  
  <p>Given a queryset/list of ID's (unknown amount how many ID's, could be None/0)</p>
  
  <p>Is there a way to get the latest row for each account, then sum the value?</p>
  
  <p>The part I'm really struggling with is only retrieving the latest row per account.</p>
  
  <p>I know I can get the accounts that are in the given queryset by doing:</p>
  
  <pre><code>accounts = [1, 4, 65]
  AccountData.objects.filter(account__in=accounts)
  </code></pre>
  
  <p>Just need to figure out how I can only get the rows where "date" is as close to "now" as possible. Thus resulting in having unique rows (only 1 row per account) </p>