title: How to get the latest 3 books from each author using django
body: <p>Using the following django models:</p>
  
  <pre><code>class Author(models.Model):
     name = models.CharField(max_length=100)
     age = models.IntegerField()
  
  class Book(models.Model):
      name = models.CharField(max_length=300)
      author = models.ForeignKey(Author)
      pubdate = models.DateField()
      class Meta:
          ordering = ('-pubdate')
  </code></pre>
  
  <p>How can i get the <strong>five latest books published by each author</strong>?</p>
  
  <p>I had considered iterate each author and get books published by the author slicing to 5.</p>
  
  <pre><code>for a in Author.objects.all():
      books = Book.objects.filter(author = a )[:5]
      print books #and/or process the entries... 
  </code></pre>
  
  <p>But, if the tables has a lot of records (maybe thousands of books), this could be slow and inefficient.</p>
  
  <p>So, is there any other way to accomplish this with django (or a sql query) ?</p>