Skip to content

Commit

Permalink
fix: multiple dropdown params (#671)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvinclav authored Aug 12, 2024
1 parent 8a35767 commit 1c5f42a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/unfold/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,14 @@ def media(self):
additional_media = forms.Media()

for filter in self.list_filter:
if not isinstance(filter, (tuple, list)):
continue

if hasattr(filter[1], "form_class") and hasattr(
filter[1].form_class, "Media"
if (
isinstance(filter, (tuple, list))
and hasattr(filter[1], "form_class")
and hasattr(filter[1].form_class, "Media")
):
additional_media += forms.Media(filter[1].form_class.Media)
elif hasattr(filter, "form_class") and hasattr(filter.form_class, "Media"):
additional_media += forms.Media(filter.form_class.Media)

return media + additional_media

Expand Down
9 changes: 8 additions & 1 deletion src/unfold/contrib/filters/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,16 @@ def choices(self, changelist: ChangeList) -> Tuple[Dict[str, Any], ...]:
)


class MultipleDropdownFilter(MultiValueMixin, DropdownFilter):
class MultipleDropdownFilter(DropdownFilter):
multiple = True

def __init__(self, request, params, model, model_admin):
self.request = request
super().__init__(request, params, model, model_admin)

def value(self):
return self.request.GET.getlist(self.parameter_name)


class ChoicesDropdownFilter(ValueMixin, DropdownMixin, admin.ChoicesFieldListFilter):
def choices(self, changelist: ChangeList):
Expand Down

0 comments on commit 1c5f42a

Please sign in to comment.