Skip to content

Commit

Permalink
Fix support for Django 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JobDoesburg committed Jul 30, 2024
1 parent e7492a5 commit 913572f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ classifiers = [
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
]
Expand Down
16 changes: 12 additions & 4 deletions src/django_admin_multi_select_filter/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def __init__(self, field, request, params, model, model_admin, field_path):
self.lookup_val = self.used_parameters.get(self.lookup_kwarg, [])
if len(self.lookup_val) == 1 and self.lookup_val[0] == "":
self.lookup_val = []
elif len(self.lookup_val) == 1 and type(self.lookup_val[0]) != str:
# In Django 5.0, we get an extra list
self.lookup_val = self.lookup_val[0]
self.lookup_val_isnull = self.used_parameters.get(self.lookup_kwarg_isnull)

self.empty_value_display = model_admin.get_empty_value_display()
Expand All @@ -30,9 +33,10 @@ def __init__(self, field, request, params, model, model_admin, field_path):
)
self.field_verboses = {}
if self.field.choices:
self.field_verboses = {field_value: field_verbose for
field_value, field_verbose in
self.field.choices}
self.field_verboses = {
field_value: field_verbose
for field_value, field_verbose in self.field.choices
}

def expected_parameters(self):
return [self.lookup_kwarg, self.lookup_kwarg_isnull]
Expand Down Expand Up @@ -91,12 +95,16 @@ def __init__(self, field, request, params, model, model_admin, field_path):
self.lookup_kwarg = "%s__%s__in" % (field_path, field.target_field.name)
self.lookup_kwarg_isnull = "%s__isnull" % field_path
values = params.get(self.lookup_kwarg, [])
if len(values) == 1 and type(values[0]) != str:
# In Django 5.0, we get an extra list
values = values[0]
self.lookup_val = values.split(",") if values else []
self.lookup_choices = self.field_choices(field, request, model_admin)

def choices(self, changelist):
yield {
"selected": self.lookup_val is None and not self.lookup_val_isnull,
"selected": (self.lookup_val is None or self.lookup_val == [])
and not self.lookup_val_isnull,
"query_string": changelist.get_query_string(
remove=[self.lookup_kwarg, self.lookup_kwarg_isnull]
),
Expand Down

0 comments on commit 913572f

Please sign in to comment.