ordering by foreign key

10 views
Skip to first unread message

Douglas Campos

unread,
May 22, 2006, 10:56:48 AM5/22/06
to django...@googlegroups.com
i have a model formed by :
vendor = foreign key
name, ver, rev, etc

how can i order by vendor first?
ordering = [ 'vendor', 'name' ] fails

any ideas?

Joseph Kocherhans

unread,
May 22, 2006, 11:03:11 AM5/22/06
to django...@googlegroups.com

Ordering by a foreign key isn't technically supported at this point,
but you can fake it. Instead of 'vendor' try 'appname_vendor.name'
where 'appname_vendor' is the name of the vendor table in your
database and 'name' is the name of the column you want to sort by.
This worked last time a checked (a few weeks ago), but no promises.
You'll probably have to add the list_select_related = True option to
your inner Admin class as well. list_select_related is documented in
the model-api docs on djangoproject.com if you want to learn more
about it.

Joseph

Reply all
Reply to author
Forward
0 new messages