Django query with distinct and order_by Django query with distinct and order_by django django

Django query with distinct and order_by


You can place on the Employer class its latest JobTitle activation date, and then order by this field without using relations.[1] The tradeoff here is a bit of data duplication, and the necessity to update employer's latest job title activation date manually when corresponding JobTitle instance changes.

Also, check this post for another solution which uses annotate().

Related questions:

[1] Queryset API distinct() does not work?