Skip to content

Instantly share code, notes, and snippets.

@ryanpitts
ryanpitts / gist:1304725
Created October 21, 2011 19:34
GROUP BY and Select MAX from each group in Django, 2 queries
'''
given a Model with:
category = models.CharField(max_length=32, choices=CATEGORY_CHOICES)
pubdate = models.DateTimeField(default=datetime.now)
<other fields>
Fetch the item from each category with the latest pubdate.
'''