Skip to content

Commit ff9b8f8

Browse files
authored
remove collapsed state (#9)
1 parent 5fd351c commit ff9b8f8

File tree

5 files changed

+4
-20
lines changed

5 files changed

+4
-20
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ from django_admin_filters import MultiChoice
8181
class MyChoicesFilter(MultiChoice):
8282
FILTER_LABEL = "Select options"
8383
BUTTON_LABEL = "Apply"
84-
is_collapsed = False
8584
```
8685

8786
- FILTER_LABEL: Filter title
8887
- BUTTON_LABEL: Title for filter apply button
89-
- is_collapsed: Filter state (collapsed/expanded) on first page load
9088

9189
## MultiChoice filter
9290

READMEru.md

-2
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ from django_admin_filters import MultiChoice
7575
class MyChoicesFilter(MultiChoice):
7676
FILTER_LABEL = "Выберите опции"
7777
BUTTON_LABEL = "Применить"
78-
is_collapsed = False
7978
```
8079

8180
- FILTER_LABEL: Заголовок фильтра
8281
- BUTTON_LABEL: Заголовок кнопки применения фильтра
83-
- is_collapsed: Состояние фильтра (свернутый/распахнутый) при первой загрузке страницы
8482

8583
## Фильтр MultiChoice
8684

django_admin_filters/base.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from django.contrib import admin
33

44

5-
class Collapsed:
5+
class Base:
66
"""Mixin class for filters with title, apply button and collapsed state."""
77

8-
is_collapsed = False
98
parameter_name = 'filter'
109
title = None
1110

@@ -18,16 +17,10 @@ def set_title(self):
1817
'parameter_name': self.parameter_name,
1918
'filter_name': self.FILTER_LABEL,
2019
'button_label': self.BUTTON_LABEL,
21-
'collapsed': self.collapsed_state,
2220
}
2321

24-
@property
25-
def collapsed_state(self):
26-
"""Return string for CSS stype."""
27-
return '' if self.is_collapsed else 'open'
2822

29-
30-
class Filter(admin.FieldListFilter, Collapsed):
23+
class Filter(admin.FieldListFilter, Base):
3124
"""Base class for filters applied to field with title, apply button and collapsed state."""
3225

3326
parameter_name_mask = 'adminfilter_'
@@ -54,7 +47,7 @@ def choices(self, changelist):
5447
raise NotImplementedError('Method choices')
5548

5649

57-
class FilterSimple(admin.SimpleListFilter, Collapsed):
50+
class FilterSimple(admin.SimpleListFilter, Base):
5851
"""Base class for filters without field with title, apply button and collapsed state."""
5952

6053
parameter_name = 'adminfilter'

django_admin_filters/templates/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<details data-filter-title="{{ title.filter_name }}" {{ title.collapsed }}>
1+
<details data-filter-title="{{ title.filter_name }}" open >
22
<summary>{{ title.filter_name }}</summary>
33
<ul>
44
{% block choices_list %}

example/admin.py

-5
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ class StatusFilter(MultiChoice):
99
"""Field status filter."""
1010

1111
FILTER_LABEL = "By status"
12-
is_collapsed = True
1312

1413

1514
class NumberFilter(MultiChoice):
1615
"""Field number filter."""
1716

1817
FILTER_LABEL = "By number"
19-
is_collapsed = True
2018

2119

2220
class ColorFilter(MultiChoiceExt):
2321
"""Property color filter."""
2422

2523
parameter_name = "color"
2624
FILTER_LABEL = "By color"
27-
is_collapsed = True
2825

2926
# https://docs.djangoproject.com/en/4.1/topics/db/queries/#complex-lookups-with-q-objects
3027
options = [
@@ -38,14 +35,12 @@ class Timestamp1Filter(DateRange):
3835
"""Field timestamp1 filter."""
3936

4037
FILTER_LABEL = "By timestamp1"
41-
is_collapsed = True
4238

4339

4440
class Timestamp2Filter(DateRangePicker):
4541
"""Field timestamp2 filter."""
4642

4743
FILTER_LABEL = "By timestamp2"
48-
is_collapsed = True
4944

5045

5146
class Admin(admin.ModelAdmin):

0 commit comments

Comments
 (0)