[Django]-Django adds an extra field to the GROUP BY clause

4👍

The problem was in the default ordering. It was specified in the Meta:

class ChartPoint(models.Model)
    ...
    class Meta:
       ordering = ['-date']

Remove the ordering and date will not be added to the GROUP BY:

speed_by_computer = ChartPoint.objects.filter(
    date__gte=start,
    date__lt=end,
).values('computer_id') \
 .annotate(hs_avg=Max('speed'))
 .order_by()

Leave a comment