Skip to content

Commit 32c2455

Browse files
committed
fix: autocomplete in django 5.0
1 parent 6470734 commit 32c2455

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

nested_admin/compat.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
See https://github.com/django/django/commit/c19b56f633e172b3c02094cbe12d28865ee57772
55
and https://code.djangoproject.com/ticket/28377
66
"""
7+
78
from collections import defaultdict, OrderedDict
89
import warnings
910

@@ -27,13 +28,19 @@ class MediaOrderConflictWarning(RuntimeWarning):
2728
CyclicDependencyError,
2829
stable_topological_sort,
2930
)
31+
32+
has_topological_sort = True
3033
except ImportError:
34+
try:
35+
from django.forms.widgets import TopologicalSorter
36+
except ImportError:
37+
has_topological_sort = False
38+
else:
39+
has_topological_sort = True
3140

3241
class CyclicDependencyError(ValueError):
3342
pass
3443

35-
stable_topological_sort = None
36-
3744

3845
class OrderedSet(_OrderedSet):
3946
def __sub__(self, other):
@@ -46,7 +53,7 @@ def __repr__(self):
4653
return "OrderedSet(%r)" % list(self)
4754

4855

49-
if MergeSafeMedia is None or stable_topological_sort is None:
56+
if MergeSafeMedia is None or not has_topological_sort:
5057

5158
def linearize_as_needed(l, dependency_graph):
5259
# Algorithm: DFS Topological sort

nested_admin/tests/admin_widgets/tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,11 @@ def test_nested_autocomplete_extra(self):
406406
self.add_inline([0, 1, [0]])
407407
select_field = self.get_field("fk3", indexes=[0, 1, [0, 0]])
408408
select_parent = select_field.find_element(By.XPATH, "parent::*")
409-
select_parent.click()
409+
self.selenium.execute_script(
410+
"return arguments[0].querySelector('.select2-selection') || arguments[0]",
411+
select_parent
412+
).click()
413+
410414
select2_is_active = self.selenium.execute_script(
411415
'return $(".select2-search__field").length > 0'
412416
)

0 commit comments

Comments
 (0)