How can I represent this simple SQL using Django ORM?
SELECT * FROM alerts a1 WHERE timestamp = (
SELECT MAX(timestamp) FROM alerts a2
WHERE a1.category = a2.category
AND a1.type = a2.type
)
The alerts table in this case is a history of all the possible alerts that happened, with a category tag on each - and the query returns the latest alerts for each category.