Yes, this is ticket #2076: http://code.djangoproject.com/ticket/2076
Until someone figures it out, a workaround would be to do
.extra(tables=['auth_user']).order_by('author__username')
(assuming that your 'author' relation point at auth.User -- the bug is
that Django doesn't pick up all the tables it needs to join, so the
call to 'extra' tells it to bring in auth_user explicitly).
--
"May the forces of evil become confused on the way to your house."
-- George Carlin
Hi dcramer,
This is slightly inelegant, but you can specify the SQL table name in
order_by():
order_by('myapp_authors.username')
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com
http://code.djangoproject.com/attachment/ticket/2210/order_by_related.diff
Judging from the comments on that ticket, I think it's a slightly
different issue; #2210 deals with fetching the Options class of the
wrong model when the related field has 'db_column' set; in that case,
it appears Django is generating the correct table list for the query,
but not the correct column list. In #2076, which I think is what's
going on here, Django generates the right column list, but has the
wrong table list. I don't think these are related.
You may be right, I looked at both tickets when I searched for a fix
before I wrote one myself and I think I submitted the patch on the
wrong ticket. I thought they were related then but maybe not. The patch
in #2210 should be for #2076.