Opened 16 years ago
Closed 16 years ago
#10451 closed (invalid)
Admin site dropdown ordering for ForeignKey doesn't work as expected
Reported by: | Leo Shklovskii | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In the case of:
from django.contrib.auth.models import User class Foo(models.Model): user = models.ForeignKey(User)
When the admin page for Foo is rendered, the select dropdown to choose users has them sorted by id, despite the fact that the UserAdmin class has:
ordering = ('username',)
I can get around this for my own models by setting ordering on the model itself but I don't want to modify or extend the existing User model and it seems reasonable for the admin site to respect the default ordering as specified in the ModelAdmin class.
Change History (4)
comment:1 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 16 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Thanks Adam, that's a great workaround, but are you also making the design decision that the ordering specified in the admin class shouldn't apply by default? That seems a little strange.
comment:4 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
No, there is no precedent anywhere in the admin for a different ModelAdmin controlling something in one ModelAdmin. It uses the default ordering on the related model by default.
You can change the ordering by overiding formfield_for_foreignkey on the ModelAdmin in django trunk.