title: Make a query to get the latest objects, excluding duplicates of obj.x
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3664708/django-whats-the-best-fastest-way-to-get-only-first-and-last-element-from-som">Django, What&#39;s the best ,fastest way to get only first and last element from something, Customer.objects.xxxx</a>  </p>
  </blockquote>
  
  
  
  <p>Hmm this is hard to explain, but this is what's happening..</p>
  
  <p>I have a model A that has x and date </p>
  
  <p>There are multiple A's with the same x and different dates.</p>
  
  <p>From:</p>
  
  <pre><code>A.x = 1 (newest)
  A.x = 1
  A.x = 1 (oldest)
  A.x = 2  
  </code></pre>
  
  <p>I want to get only the newest of each x, in this case the first one, and the last one, excluding the older x=1 duplicates. </p>
  
  <p>I've thought of doing some nasty loops or using itertools, but I'm not sure what's the best way to achieve this. </p>
  
  <p>Any help is appreciated.</p>