2

I have a model table like this

Table A


Fields A, B, C, D, E (5 Fields)

I want to group by field B and min by field C so in the end, i need to have a full queryset like

A, B, C, D, E, Min(C)GroupBY(B) (6 Fields).

I know about A.objects.values(B).annotate(min(C)) but it returns only 2 fields and not a full row.

My requirements are to use only pure Django ORM or extra. I can't use raw SQL (limitations for filter, rawqueryset etc) cause i need a queryset to import to Django-Tables2.

Any advice how i can achieve this?

bezkos
  • 21
  • 1
  • 3
  • If you want full rows you need a way to filter which row from each group you want. i.e. `qs.order_by('created_date').distinct('name')` is choosing the one with the min `created_date` when grouping by `name`. – fips May 21 '17 at 23:05
  • Yes i know this way (is for PostgreSQL only but anyway i use PostgreSQL) but i ll take only a min row per group and not all rows like i described above. – bezkos May 21 '17 at 23:22

0 Answers0