Skip to content

Commit 08a0b92

Browse files
maqniusjacobtylerwalls
authored andcommitted
Fixed #36468 -- Fixed failure to close popup when adding a related object in the admin.
The issue manifested when there were multiple relations and only some of them participated in a filter_horizontal. Regression in cd0479f.
1 parent 4cecf30 commit 08a0b92

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@
111111
option = new Option(newRepr, newId);
112112
select.options.add(option);
113113
// Update SelectBox cache for related fields.
114-
if (window.SelectBox !== undefined && !SelectBox.cache[currentSelect.id]) {
114+
if (
115+
window.SelectBox !== undefined
116+
&& !SelectBox.cache[currentSelect.id]
117+
// Only if SelectBox is managing that field.
118+
&& SelectBox.cache[select.id]
119+
) {
115120
SelectBox.add_to_cache(select.id, option);
116121
// Sort if there are any groups present
117122
if (SelectBox.cache[select.id].some(item => item.group)) {

tests/admin_views/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,3 +1196,7 @@ def __str__(self):
11961196
class CamelCaseRelatedModel(models.Model):
11971197
m2m = models.ManyToManyField(CamelCaseModel, related_name="m2m")
11981198
fk = models.ForeignKey(CamelCaseModel, on_delete=models.CASCADE, related_name="fk")
1199+
# Add another relation that will not participate in filter_horizontal.
1200+
fk2 = models.ForeignKey(
1201+
CamelCaseModel, on_delete=models.CASCADE, related_name="fk2"
1202+
)

0 commit comments

Comments
 (0)