Django GROUP BY without aggregate
I would like to write the following query in Postgresql using Django ORM:
SELECT t.id, t.field1 FROM mytable t JOIN ... JOIN ... WHERE .... GROUP BY id
Note that there is NO aggregate function (like SUM, COUNT etc.) in the SELECT part. By the way, it's a perfectly legal SQL to GROUP BY primary key only in Postgresql.
How do I write it in Django ORM?
I saw workarounds like adding .annotate(dummy=Count('*')) to the queryset (but it slows down the execution) or introducing a dummy custom aggregate function (but it's a dirty hack). How to do it in a clean way?