title: How to retrieve the first X objects with unique attribute value
body: <p>In one of my Django application, I am looking for an elegant and performant solution for a problem that could be described with the following example :</p>
  
  <p>Given these objects:</p>
  
  <pre><code>class Author(models.Model):
      name = models.CharField()
  
  class Book(models.Model):
      collection = models.ForeignKey(Collection)
      publication = models.DateField()
  
  class Collection(models.Model):
      name = models.CharField()
      author = models.ForeignKey(Author)
  </code></pre>
  
  <p>I would like to retrieve the 4 (or any other small number) latest published books but I want to have also 4 different authors. Meaning that if the 2 latest published books are from the same author, I only want to get one in my top 4 et leave 3 spots for other authors.</p>
  
  <p>I have thought of doing this in multiple steps, retrieving latest publication, then testing one by one and storing the author value and if it was present multiple time i would retrieve more latest publication... but this being done on my home page, i need this code to be as efficient as possible.</p>
  
  <p>Any help would be highly appreciated.
  Thanks   </p>