File tree 6 files changed +69
-2
lines changed
django_admin_listfilter_dropdown
templates/django_admin_listfilter_dropdown
6 files changed +69
-2
lines changed Original file line number Diff line number Diff line change
1
+ include LICENSE
2
+ include README.md
3
+ recursive-include django_admin_listfilter_dropdown/templates *
Original file line number Diff line number Diff line change @@ -30,11 +30,16 @@ INSTALLED_APPS = (
30
30
Use in ` admin.py ` :
31
31
32
32
``` py
33
- from django_admin_listfilter_dropdown.filters import DropdownFilter
33
+ from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter
34
34
35
35
class EntityAdmin (admin .ModelAdmin ):
36
36
...
37
- list_filter = ((' fieldname' , DropdownFilter),)
37
+ list_filter = (
38
+ # for ordinary fields
39
+ (' a_charfield' , DropdownFilter),
40
+ # for related fields
41
+ (' a_foreignkey_field' , RelatedDropdownFilter),
42
+ )
38
43
```
39
44
40
45
# Credits
Original file line number Diff line number Diff line change
1
+ from django .contrib .admin .filters import AllValuesFieldListFilter , RelatedFieldListFilter
2
+
3
+ class DropdownFilter (AllValuesFieldListFilter ):
4
+ template = 'django_admin_listfilter_dropdown/dropdown_filter.html'
5
+
6
+ class RelatedDropdownFilter (RelatedFieldListFilter ):
7
+ template = 'django_admin_listfilter_dropdown/dropdown_filter.html'
Original file line number Diff line number Diff line change
1
+ {% load i18n %}
2
+ < script type ="text/javascript "> var go_from_select = function ( opt ) { window . location = window . location . pathname + opt } ; </ script >
3
+ < h3 > {% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}</ h3 >
4
+ < ul class ="admin-filter-{{ title|cut:' ' }} ">
5
+ {% if choices|slice:"4:" %}
6
+ < li >
7
+ < select style ="width: 95%; "
8
+ onchange ="go_from_select(this.options[this.selectedIndex].value) ">
9
+ {% for choice in choices %}
10
+ < option {% if choice.selected %} selected ="selected "{% endif %}
11
+ value ="{{ choice.query_string|iriencode }} "> {{ choice.display }}</ option >
12
+ {% endfor %}
13
+ </ select >
14
+ </ li >
15
+ {% else %}
16
+
17
+ {% for choice in choices %}
18
+ < li {% if choice.selected %} class ="selected "{% endif %} >
19
+ < a href ="{{ choice.query_string|iriencode }} "> {{ choice.display }}</ a > </ li >
20
+ {% endfor %}
21
+
22
+ {% endif %}
23
+ </ ul >
Original file line number Diff line number Diff line change
1
+ # encoding: utf-8
2
+
3
+ import os
4
+ from setuptools import find_packages , setup
5
+
6
+ # allow setup.py to be run from any path
7
+ os .chdir (os .path .normpath (os .path .join (os .path .abspath (__file__ ), os .pardir )))
8
+
9
+ setup (
10
+ name = 'django-admin-list-filter-dropdown' ,
11
+ version = '1.0.0' ,
12
+ packages = find_packages (),
13
+ include_package_data = True ,
14
+ license = 'MIT License' ,
15
+ description = 'Use dropdowns in Django admin list filter' ,
16
+ url = 'https://github.com/mrts/django-admin-list-filter-dropdown' ,
17
+ author = 'Mart Sõmermaa' ,
18
+ author_email = "mrts.pydev at gmail dot com" ,
19
+ classifiers = [
20
+ 'Environment :: Web Environment' ,
21
+ 'Framework :: Django' ,
22
+ 'Intended Audience :: Developers' ,
23
+ 'License :: OSI Approved :: MIT License' ,
24
+ 'Operating System :: OS Independent' ,
25
+ 'Programming Language :: Python' ,
26
+ 'Topic :: Internet :: WWW/HTTP' ,
27
+ 'Topic :: Internet :: WWW/HTTP :: Dynamic Content' ,
28
+ ],
29
+ )
You can’t perform that action at this time.
0 commit comments