Skip to content

Instantly share code, notes, and snippets.

View Zakui's full-sized avatar

Jules Thea Zakui

View GitHub Profile
@Zakui
Zakui / gist:dc1acbb9c1b0ccbf08648f2c6eb9e6c2
Created November 7, 2018 10:43 — forked from ryanpitts/gist:1304725
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.
'''