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 Alex Gaynor, 16 years ago

Resolution: invalid
Status: newclosed

You can change the ordering by overiding formfield_for_foreignkey on the ModelAdmin in django trunk.

comment:2 by Leo Shklovskii, 16 years ago

Resolution: invalid
Status: closedreopened

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:3 by Leo Shklovskii, 16 years ago

Er, I meant Alex, sorry about that.

comment:4 by Alex Gaynor, 16 years ago

Resolution: invalid
Status: reopenedclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top