Opened 9 years ago

Closed 4 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 Changed 9 years ago by Honza Král

Keywords: nfa-someday added
Needs documentation: set
Needs tests: set
Patch needs improvement: unset
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 Changed 8 years ago by Jason Green <Django@…>

Cc: DJango@… added

comment:3 Changed 6 years ago by Julien Phalip

Type: Bug

comment:4 Changed 6 years ago by Brillgen Developers

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 Changed 6 years ago by anonymous

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 Changed 5 years ago by anonymous

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 Changed 5 years ago by anonymous

Resolution: needsinfo
Status: closedreopened

comment:7 Changed 5 years ago by Brillgen Developers

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 Changed 5 years ago by Julien Phalip

UI/UX: unset

#16641 is a duplicate.

comment:9 Changed 5 years ago by sebastien@…

Cc: sebastien@… added

comment:10 Changed 5 years ago by Carl Meyer

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 Changed 5 years ago by thauber

Owner: changed from nobody to thauber
Status: reopenednew

comment:12 Changed 4 years ago by fisadev

Owner: changed from thauber to fisadev
Status: newassigned

comment:13 Changed 4 years ago by fisadev

Has patch: set
Needs tests: unset

Proposed implementation on pull request 806:

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

comment:14 Changed 4 years ago by fisadev

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

comment:15 Changed 4 years ago by fisadev

Keywords: #sprints-django-ar added

comment:16 Changed 4 years ago by Ramiro Morales <cramm0@…>

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