Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrts/django-admin-list-filter-dropdown
Use dropdowns in Django admin list filter
https://github.com/mrts/django-admin-list-filter-dropdown
django django-admin filter-dropdown node
Last synced: 2 days ago
JSON representation
Use dropdowns in Django admin list filter
- Host: GitHub
- URL: https://github.com/mrts/django-admin-list-filter-dropdown
- Owner: mrts
- License: mit
- Created: 2016-09-21T12:39:36.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-24T20:53:09.000Z (about 1 year ago)
- Last Synced: 2024-04-24T12:29:22.767Z (9 months ago)
- Topics: django, django-admin, filter-dropdown, node
- Language: Python
- Homepage:
- Size: 20.5 KB
- Stars: 306
- Watchers: 8
- Forks: 44
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-admin-list-filter-dropdown
A Django admin filter implementation that renders as a dropdown.
If you have more than ten values for a field that you want to filter by in
Django admin, the filtering sidebar gets long, cluttered and hard to use.This app contains the `DropdownFilter` class that renders as a drop-down in the
filtering sidebar to avoid this problem.# Usage
Install:
```sh
pip install django-admin-list-filter-dropdown
```Enable in `settings.py`:
```py
INSTALLED_APPS = (
...
'django_admin_listfilter_dropdown',
...
)```
Use in `admin.py`:
```py
from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter, ChoiceDropdownFilterclass EntityAdmin(admin.ModelAdmin):
...
list_filter = (
# for ordinary fields
('a_charfield', DropdownFilter),
# for choice fields
('a_choicefield', ChoiceDropdownFilter),
# for related fields
('a_foreignkey_field', RelatedDropdownFilter),
)
```Example of a custom filter that uses the provided template:
```py
class CustomFilter(SimpleListFilter):
template = 'django_admin_listfilter_dropdown/dropdown_filter.html'def lookups(self, request, model_admin):
...def queryset(self, request, queryset):
...
```# Example
Here's what it looks like:
![Screenshot of dropdown admin filter](https://raw.githubusercontent.com/mrts/django-admin-list-filter-dropdown/master/docs/list-filter-dropdown.png)
# Credits
Based on [this StackOverflow question](http://stackoverflow.com/a/20900314/258772) and
[code from FeinCMS](https://github.com/feincms/feincms/blob/master/feincms/templates/admin/filter.html).