├── .gitignore ├── LICENSE ├── MANIFEST.in ├── README.md ├── django_admin_listfilter_dropdown ├── __init__.py ├── filters.py └── templates │ └── django_admin_listfilter_dropdown │ └── dropdown_filter.html ├── docs ├── list-filter-dropdown.png ├── publishing.md └── register-with-converting-README.md-to-reStructuredTxt.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Mart Sõmermaa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.md 3 | recursive-include django_admin_listfilter_dropdown/templates * 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # django-admin-list-filter-dropdown 2 | 3 | A Django admin filter implementation that renders as a dropdown. 4 | 5 | If you have more than ten values for a field that you want to filter by in 6 | Django admin, the filtering sidebar gets long, cluttered and hard to use. 7 | 8 | This app contains the `DropdownFilter` class that renders as a drop-down in the 9 | filtering sidebar to avoid this problem. 10 | 11 | # Usage 12 | 13 | Install: 14 | 15 | ```sh 16 | pip install django-admin-list-filter-dropdown 17 | ``` 18 | 19 | Enable in `settings.py`: 20 | 21 | ```py 22 | INSTALLED_APPS = ( 23 | ... 24 | 'django_admin_listfilter_dropdown', 25 | ... 26 | ) 27 | 28 | ``` 29 | 30 | Use in `admin.py`: 31 | 32 | ```py 33 | from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter, ChoiceDropdownFilter 34 | 35 | class EntityAdmin(admin.ModelAdmin): 36 | ... 37 | list_filter = ( 38 | # for ordinary fields 39 | ('a_charfield', DropdownFilter), 40 | # for choice fields 41 | ('a_choicefield', ChoiceDropdownFilter), 42 | # for related fields 43 | ('a_foreignkey_field', RelatedDropdownFilter), 44 | ) 45 | ``` 46 | 47 | Example of a custom filter that uses the provided template: 48 | 49 | ```py 50 | class CustomFilter(SimpleListFilter): 51 | template = 'django_admin_listfilter_dropdown/dropdown_filter.html' 52 | 53 | def lookups(self, request, model_admin): 54 | ... 55 | 56 | def queryset(self, request, queryset): 57 | ... 58 | ``` 59 | 60 | # Example 61 | 62 | Here's what it looks like: 63 | 64 | ![Screenshot of dropdown admin filter](https://raw.githubusercontent.com/mrts/django-admin-list-filter-dropdown/master/docs/list-filter-dropdown.png) 65 | 66 | # Credits 67 | 68 | Based on [this StackOverflow question](http://stackoverflow.com/a/20900314/258772) and 69 | [code from FeinCMS](https://github.com/feincms/feincms/blob/master/feincms/templates/admin/filter.html). 70 | -------------------------------------------------------------------------------- /django_admin_listfilter_dropdown/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrts/django-admin-list-filter-dropdown/8ab1575dcd3cb9b28a80cc07695cec65fa85dfad/django_admin_listfilter_dropdown/__init__.py -------------------------------------------------------------------------------- /django_admin_listfilter_dropdown/filters.py: -------------------------------------------------------------------------------- 1 | from django.contrib.admin.filters import ( 2 | SimpleListFilter, 3 | AllValuesFieldListFilter, 4 | ChoicesFieldListFilter, 5 | RelatedFieldListFilter, 6 | RelatedOnlyFieldListFilter 7 | ) 8 | 9 | 10 | class SimpleDropdownFilter(SimpleListFilter): 11 | template = 'django_admin_listfilter_dropdown/dropdown_filter.html' 12 | 13 | 14 | class DropdownFilter(AllValuesFieldListFilter): 15 | template = 'django_admin_listfilter_dropdown/dropdown_filter.html' 16 | 17 | 18 | class ChoiceDropdownFilter(ChoicesFieldListFilter): 19 | template = 'django_admin_listfilter_dropdown/dropdown_filter.html' 20 | 21 | 22 | class RelatedDropdownFilter(RelatedFieldListFilter): 23 | template = 'django_admin_listfilter_dropdown/dropdown_filter.html' 24 | 25 | 26 | class RelatedOnlyDropdownFilter(RelatedOnlyFieldListFilter): 27 | template = 'django_admin_listfilter_dropdown/dropdown_filter.html' 28 | -------------------------------------------------------------------------------- /django_admin_listfilter_dropdown/templates/django_admin_listfilter_dropdown/dropdown_filter.html: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | 3 |

{% blocktrans with title as filter_title %} By {{ filter_title }} {% endblocktrans %}

4 | 24 | -------------------------------------------------------------------------------- /docs/list-filter-dropdown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrts/django-admin-list-filter-dropdown/8ab1575dcd3cb9b28a80cc07695cec65fa85dfad/docs/list-filter-dropdown.png -------------------------------------------------------------------------------- /docs/publishing.md: -------------------------------------------------------------------------------- 1 | # Publishing 2 | 3 | See https://packaging.python.org/tutorials/packaging-projects/ 4 | 5 | ## Steps 6 | 7 | ```sh 8 | pip install --user --upgrade setuptools wheel 9 | pip install --user --upgrade twine 10 | 11 | python setup.py sdist bdist_wheel 12 | twine upload -r pypi dist/* 13 | ``` 14 | 15 | ## ~/.pypirc 16 | 17 | ```ini 18 | [distutils] 19 | index-servers = pypi pypitest 20 | 21 | [pypi] 22 | repository: https://upload.pypi.org/legacy/ 23 | username: mrts 24 | password: ... 25 | 26 | [pypitest] 27 | repository: https://test.pypi.org/legacy/ 28 | username: mrts 29 | password: ... 30 | ``` 31 | -------------------------------------------------------------------------------- /docs/register-with-converting-README.md-to-reStructuredTxt.py: -------------------------------------------------------------------------------- 1 | import pandoc 2 | import os 3 | 4 | doc = pandoc.Document() 5 | doc.markdown = open('README.md').read() 6 | with open('README.txt','w+') as f: 7 | f.write(doc.rst) 8 | os.system("python setup.py register") 9 | os.remove('README.txt') 10 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | import os 4 | from setuptools import find_packages, setup 5 | 6 | VERSION = '1.0.3' 7 | 8 | # allow setup.py to be run from any path 9 | os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) 10 | 11 | description = 'Use dropdowns in Django admin list filter' 12 | long_description = description 13 | if os.path.exists('README.txt'): 14 | long_description = open('README.txt').read() 15 | 16 | setup( 17 | name='django-admin-list-filter-dropdown', 18 | version=VERSION, 19 | packages=find_packages(), 20 | include_package_data=True, 21 | license='MIT License', 22 | description=description, 23 | long_description=long_description, 24 | url='https://github.com/mrts/django-admin-list-filter-dropdown', 25 | download_url='https://github.com/mrts/django-admin-list-filter-dropdown/archive/%s.zip' % VERSION, 26 | author='Mart Sõmermaa', 27 | author_email="mrts.pydev@gmail.com", 28 | keywords=['django', 'admin', 'filter', 'dropdown'], 29 | classifiers=[ 30 | 'Environment :: Web Environment', 31 | 'Framework :: Django', 32 | 'Intended Audience :: Developers', 33 | 'License :: OSI Approved :: MIT License', 34 | 'Operating System :: OS Independent', 35 | 'Programming Language :: Python', 36 | 'Topic :: Internet :: WWW/HTTP', 37 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 38 | ], 39 | ) 40 | --------------------------------------------------------------------------------