Code

Opened 6 years ago

Closed 17 months ago

#6585 closed Bug (fixed)

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

Reported by: gwilson Owned by: fisadev
Component: contrib.admin Version: newforms-admin
Severity: Normal Keywords: #sprints-django-ar
Cc: DJango@…, brillgen, 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',)

Attachments (0)

Change History (17)

comment:1 Changed 6 years ago by Honza_Kral

  • Keywords nfa-someday added
  • Needs documentation set
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Someday/Maybe
  • Version changed from SVN to newforms-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 6 years ago by Jason Green <Django@…>

  • Cc DJango@… added

comment:3 Changed 3 years ago by julien

  • Type set to Bug

comment:4 Changed 3 years ago by brillgen

  • Cc brillgen added
  • Severity set to 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 3 years ago by anonymous

  • Severity set to 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 3 years ago by anonymous

  • Resolution set to needsinfo
  • Status changed from new to closed
  • Triage Stage changed from Someday/Maybe to Design 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 3 years ago by anonymous

  • Resolution needsinfo deleted
  • Status changed from closed to reopened

comment:7 Changed 3 years ago by brillgen

  • 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 3 years ago by julien

  • UI/UX unset

#16641 is a duplicate.

comment:9 Changed 3 years ago by sebastien@…

  • Cc sebastien@… added

comment:10 Changed 3 years ago by carljm

  • Keywords nfa-someday removed
  • Triage Stage changed from Design decision needed to Accepted

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

  • Owner changed from nobody to thauber
  • Status changed from reopened to new

comment:12 Changed 17 months ago by fisadev

  • Owner changed from thauber to fisadev
  • Status changed from new to assigned

comment:13 Changed 17 months 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 17 months ago by fisadev

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

comment:15 Changed 17 months ago by fisadev

  • Keywords #sprints-django-ar added

comment:16 Changed 17 months ago by Ramiro Morales <cramm0@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.