How to select from select distinct ?


I’m using django-tables2 with django-filter
in the table, I always want the results grouped by build_type_id
in got class ResultsFilter(FilterSet) and there i add to qs distinct part:

    def qs(self):
        parent = super().qs
        return parent.distinct('build_type_id').order_by('build_type_id', '-id')

and all works fine filtering working ok, problem is with ordering
I would like to be able to sort the results from distinct select in django-table2

i go postgresql query which works

select * from (
    ON ("builds_results"."build_type_id") "builds_results"."id",
   FROM "builds_results"
   ORDER BY "builds_results"."build_type_id" ASC, "builds_results"."id" DESC
) t
order by "t"."created_at" ASC

how can i get this effect in django ?

no one had a problem similar to mine?

if any one need sort distinct result

def qs(self):
    parent = super().qs
    q = parent.distinct('product__release', 'name').order_by('product__release', 'name', '-id')
    return sorted(q, key=operator.attrgetter('created_at'), reverse=True)