Opened 15 years ago

Closed 2 years ago

#11803 closed Bug (fixed)

Admin does not update every ForeignKey select of the same model

Reported by: danilo <danilo.cabello@…> Owned by: Marcelo Galigniana
Component: contrib.admin Version: dev
Severity: Normal Keywords: admin select foreignkey
Cc: aaboffill@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Consider I have the following models:

class City(models.Model):
  name = models.CharField(80)
  state  = models.CharField(2)

class Person(models.Model):
  living_city = models.ForeignKey(City)
  born_city = models.ForeignKey(City, related_name='born_city_set')

When I go to admin to add a new Person, I have the option to add a city at living_city select and born_city select, if I add a city at living_city select, for example, the born_city select does not update automatically, it remains empty or without the new option.

Change History (13)

comment:1 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

comment:3 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by googol, 12 years ago

I'd like to vote for this feature as it is crucial for our projects. Without it customers have to edit the entities first (City) they will refer to in other models (Person) which is very bad from a usability point of view!

comment:6 by roland, 12 years ago

second vote

comment:7 by Adonys Alea Boffill, 7 years ago

Cc: aaboffill@… added

I think that is a little difficult to find a simple and elegant way to fix this ticket.
The Select fields are updated in RelatedObjectLookups.js when the popup is closed after to add the new record. In order to update all fields related with the same model, is necessary to have at least something to identify all HTML elements with the same model, something like data-model-ref="". Now this is a little more easy with the new template-based widget rendering, because is easy to add the attribute to the template.
But to make this simple change in the template, is necessary to update all tests related with the html content of widgets. And I don't know if to add a new attribute to the field widget template it's finally convenient or worthwhile.

If finally to add something like data-model-ref="" in the field widget template is not a bad idea, I can work on a solution.

comment:8 by Marcelo Galigniana, 2 years ago

Owner: changed from nobody to Marcelo Galigniana
Status: newassigned

comment:9 by Marcelo Galigniana, 2 years ago

Has patch: set
Last edited 2 years ago by Marcelo Galigniana (previous) (diff)

comment:10 by Asif Saifuddin Auvi, 2 years ago

Version: 1.1dev

comment:11 by Carlton Gibson, 2 years ago

Patch needs improvement: set

The suggest patch looks kind of neat, so 👍
I think limit_choices_to (and maybe other wiggles) need consideration for it to be 100%

comment:12 by Carlton Gibson, 2 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:13 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In c72f6f3:

Fixed #11803 -- Allowed admin select widgets to display new related objects.

Adjusted admin javascript to add newly created related objects to
already loaded select widgets.

In this version, applies only where limit_choices_to is not set.

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