Skip to content

Commit ad58415

Browse files
author
Mart Sõmermaa
committed
Add implementation
1 parent f31b253 commit ad58415

File tree

6 files changed

+69
-2
lines changed

6 files changed

+69
-2
lines changed

MANIFEST.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include LICENSE
2+
include README.md
3+
recursive-include django_admin_listfilter_dropdown/templates *

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,16 @@ INSTALLED_APPS = (
3030
Use in `admin.py`:
3131

3232
```py
33-
from django_admin_listfilter_dropdown.filters import DropdownFilter
33+
from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter
3434

3535
class EntityAdmin(admin.ModelAdmin):
3636
...
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+
)
3843
```
3944

4045
# Credits

django_admin_listfilter_dropdown/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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>

setup.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
)

0 commit comments

Comments
 (0)