Skip to content

Commit

Permalink
add more_admin_filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Svyat committed Nov 16, 2023
1 parent 9c24ff0 commit d9797af
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
18 changes: 16 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ python = ">=3.7.2,<4.0"
Django = ">=3"
django-polymorphic = "^3"
celery = ">=4.4"
django-more-admin-filters = "^1.7"

[tool.poetry.group.dev.dependencies]
flake8 = "^5.0.4"
Expand Down
1 change: 1 addition & 0 deletions tests/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'more_admin_filters',
'polymorphic',
'triggers',
'tests.app',
Expand Down
6 changes: 4 additions & 2 deletions triggers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib import admin
from django.utils.html import format_html_join
from django.utils.translation import gettext_lazy as _
from more_admin_filters import MultiSelectRelatedOnlyFilter
from polymorphic.admin import PolymorphicInlineSupportMixin, StackedPolymorphicInline
from polymorphic.models import PolymorphicModel

Expand Down Expand Up @@ -52,7 +53,7 @@ class EventInline(StackedPolymorphicInline):
child_inlines = generate_child_inlines(Event)


class RelatedOnlyFieldListFilter(admin.RelatedOnlyFieldListFilter):
class RelatedOnlyFieldMultiListFilter(MultiSelectRelatedOnlyFilter):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.title = self.__class__.__dict__['title']
Expand All @@ -64,7 +65,8 @@ def field_choices(self, field, request, model_admin) -> List[Tuple[str, str]]:


def create_related_filter(title):
return type('_RelatedFilter', (RelatedOnlyFieldListFilter,), {'title': title})
return type('_RelatedFilter', (RelatedOnlyFieldMultiListFilter,), {'title': title})



@admin.register(Trigger)
Expand Down

0 comments on commit d9797af

Please sign in to comment.