Opened 17 years ago

Closed 12 years ago

#6585 closed Bug (fixed)

admin foreignkey dropdown does not adhere to model's admin ordering

Reported by: Gary Wilson Owned by: fisadev
Component: contrib.admin Version: newforms-admin
Severity: Normal Keywords: #sprints-django-ar
Cc: DJango@…, Brillgen Developers, sebastien@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This doesn't set ordering in the dropdown (but I would expect it to):

class Admin:
    ordering = ('last_name',)

Meta ordering, however, does work:

class Meta:
    ordering = ('last_name',)

Change History (17)

comment:1 by Honza Král, 17 years ago

Keywords: nfa-someday added
Needs documentation: set
Needs tests: set
Triage Stage: UnreviewedSomeday/Maybe
Version: SVNnewforms-admin

Marking it as someday. It is quite a tricky thing to inside newforms-admin and we need to wait for the code to mature a bit.

comment:2 by Jason Green <Django@…>, 17 years ago

Cc: DJango@… added

comment:3 by Julien Phalip, 14 years ago

Type: Bug

comment:4 by Brillgen Developers, 14 years ago

Cc: Brillgen Developers added
Severity: Normal

As a simpler and more flexible fix, would it be better if we had a field called let's say related_ordering = { 'fk_field_name': 'order_field' } ...this would allow diff. models to have diff order in FK drop down. I can contribute this patch if this direction gets blessed.

comment:4 by anonymous, 14 years ago

Severity: Normal

Wouldn't it be extremely simple to add an admin field called let's say

related_ordering = {'field_name': 'order_field'}

in the admin model in which the foreign key is instead of looking it up from the admin of the foreign key model?

That should make this a much simpler implementation while having flexibility to have different order in different model admins which have the foreign key to the same model but need different order in drop down.

comment:5 by anonymous, 14 years ago

Resolution: needsinfo
Status: newclosed
Triage Stage: Someday/MaybeDesign decision needed

Changing stage to get this direction of coding blessed by the community...want to avoid working on a patch if the design itself is not ok with everyone...

comment:6 by anonymous, 14 years ago

Resolution: needsinfo
Status: closedreopened

comment:7 by Brillgen Developers, 14 years ago

Easy pickings: unset

Taking responsibility for this suggestion (by being logged in while commenting ;) :

Wouldn't it be extremely simple to add an admin field called let's say

related_ordering = {'field_name': 'order_field'}

in the admin model in which the foreign key is instead of looking it up from the admin of the foreign key model?

That should make this a much simpler implementation while having flexibility to have different order in different model admins which have the foreign key to the same model but need different order in drop down.

comment:8 by Julien Phalip, 13 years ago

UI/UX: unset

#16641 is a duplicate.

comment:9 by sebastien@…, 13 years ago

Cc: sebastien@… added

comment:10 by Carl Meyer, 13 years ago

Keywords: nfa-someday removed
Triage Stage: Design decision neededAccepted

The original report here is correct, the ModelAdmin ordering should take precedence if set, even for related-field dropdowns. We don't need to add additional complexity in the form of new options specifically for related fields; customization at that level is already possible by overriding methods on the ModelAdmin of the model with the FK.

comment:11 by thauber, 13 years ago

Owner: changed from nobody to thauber
Status: reopenednew

comment:12 by fisadev, 12 years ago

Owner: changed from thauber to fisadev
Status: newassigned

comment:13 by fisadev, 12 years ago

Has patch: set
Needs tests: unset

Proposed implementation on pull request 806:

https://github.com/django/django/pull/806

comment:14 by fisadev, 12 years ago

(pull request done as part of #sprints-django-ar :)

comment:15 by fisadev, 12 years ago

Keywords: #sprints-django-ar added

comment:16 by Ramiro Morales <cramm0@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In d9330d5be2ee60b208dcab2616eb164ea2e6bf36:

Fixed #6585 -- Admin relationship widgets: Respect ordering defined by target model's ModelAdmin.

Thanks Gary Wilson for the report and Juan Pedro Fisanotti, Carlos
Matías de la Torre for the fix.

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