In my django project i have to implement a groupped query with ORM and order results for a specific field. I do this:
a = tt.objects.filter(thread_status = 'DEAD').select_related().distinct('thread_stag').order_by('-id')[0:20]
but the response is an error:
ProgrammingError: SELECT DISTINCT ON expressions must match initial ORDER BY expressions
How can i do distinct and order_by in same query on different columns?
thanks in advance