title: django querset filter foreign key select first record
body: <p>I have a History model like below</p>
  
  <pre><code>class History(models.Model):
  
      class Meta:
          app_label = 'subscription'
          ordering = ['-start_datetime']
  
      subscription = models.ForeignKey(Subscription, related_name='history')
  
      FREE = 'free'
      Premium = 'premium'
      SUBSCRIPTION_TYPE_CHOICES = ((FREE, 'Free'), (Premium, 'Premium'),)
      name = models.CharField(max_length=32, choices=SUBSCRIPTION_TYPE_CHOICES, default=FREE)
  
      start_datetime = models.DateTimeField(db_index=True)
      end_datetime = models.DateTimeField(db_index=True, blank=True, null=True)
      cancelled_datetime = models.DateTimeField(blank=True, null=True)
  </code></pre>
  
  <p>Now i have a queryset filtering like below</p>
  
  <pre><code>users = get_user_model().objects.all()
  queryset = users.exclude(subscription__history__end_datetime__lt=timezone.now())
  </code></pre>
  
  <p>The issue is that in the exclude above it is checking end_datetime for all the rows for a particular history object. But i only want to compare it with first row of history object.</p>
  
  <p>Below is how a particular history object looks like. So i want to write a queryset filter which can do datetime comparison on first row only.</p>
  
  <p><a href="https://i.stack.imgur.com/Oqr2F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Oqr2F.png" alt="enter image description here"></a></p>