Opened 11 years ago

Last modified 3 years ago

#11803 new Bug

Admin does not update every ForeignKey select of the same model

Reported by: danilo <danilo.cabello@…> Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Normal Keywords: admin select foreignkey
Cc: aaboffill@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


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 (7)

comment:1 Changed 10 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:2 Changed 9 years ago by Julien Phalip

Severity: Normal
Type: Bug

comment:3 Changed 8 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 8 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 8 years ago by googol

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 Changed 8 years ago by roland

second vote

comment:7 Changed 3 years ago by Adonys Alea Boffill

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.

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