title: Django Query That Get Most Recent Objects From Different Categories
body: <p>I have two models <code>A</code> and <code>B</code>. All <code>B</code> objects have a foreign key to an <code>A</code> object. Given a set of <code>A</code> objects, is there anyway to use the ORM to get a set of <code>B</code> objects containing the most recent object created for each <code>A</code> object.</p>
  
  <p>Here's an simplified example:</p>
  
  <pre class="lang-py prettyprint-override"><code>class Bakery(models.Model):
      town = models.CharField(max_length=255)
  
  class Cake(models.Model):
      bakery = models.ForeignKey(Bakery, on_delete=models.CASCADE)
      baked_at = models.DateTimeField()
  </code></pre>
  
  <p>So I'm looking for a query that returns the most recent cake baked in each bakery in Anytown, USA.</p>