﻿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
29669	admin.E033 incorrectly raised when adding a calculated field in the 'ordering' tuple of a ModelAdmin	Javier Abadia Miranda	Hasan Ramezani	"Consider a simple Django app with two models Blog and Author:

{{{
class Blog(models.Model):
    title = models.CharField(max_length=200, default='no title')
    author = models.ForeignKey(to='Author', on_delete=models.CASCADE)

    def __unicode__(self):
        return ""[%d] %s"" % (self.pk, self.title,)


class Author(models.Model):
    name = models.CharField(max_length=200)

    def __unicode__(self):
        return ""[%d] %s"" % (self.pk, self.name,)

}}}

Consider that I want to order the Author changelist page in the admin by Blog count


{{{
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
    list_display = ('name', 'blog_count')
    ordering = ('name', 'blog_count')  # this line causes an admin.E033 error to be reported on startup

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        return qs.annotate(_blog_count=Count('blog'))

    def blog_count(self, obj):
        return obj._blog_count

    blog_count.admin_order_field = '_blog_count'

}}}

If the ordering tuple contains only ('name',), then the app starts correctly and the list can be sorted by name of blog count clicking on the list headers.
However, if we want a default ordering by blog_count, the check system complains about 'blog_count' or '_blog_count' not being a field of the model.

The admin changelist page supports ordering by a calculated field and it should also be allowed as a default ordering for the page.

I think the issue is near line https://github.com/django/django/blob/7eb556a6c2b2ac9313158f8b812eebea02a43f20/django/contrib/admin/checks.py#L522
"	Bug	closed	contrib.admin	2.1	Normal	duplicate	admin, ordering		Accepted	1	0	0	0	0	0
