﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29539	Cannot use Aggregation function in Model.Meta.ordering	wilhelmhb	nobody	"Modifying the example from [https://docs.djangoproject.com/en/2.0/topics/db/queries/#] to add ordering:
{{{
from django.db import models

class Author(models.Model):
    name = models.CharField(max_length=200)

class Entry(models.Model):
    headline = models.CharField(max_length=255)
    authors = models.ManyToManyField(Author)

    def __str__(self):
        return self.headline

    class Meta:
        ordering = [
            models.Min('authors__id').asc(),
            models.Max('authors__id').asc()
        ]
}}}

The query to get entries will fail with a {{{ProgrammingError}}}: the SQL query doesn't contain the {{{GROUP BY}}} clause.
As aggregation functions are QueryExpression objects, and the ordering field handles QueryExpressions since Django 2.0, it should work."	Bug	closed	Database layer (models, ORM)	2.0	Normal	wontfix	ordering, query expression, aggregation function	wilhelmhb Can Sarıgöl	Accepted	1	0	0	0	0	0
