Welcome to django-admin-filter
Description
Django-admin-filter is a generic form-based filter for the django-admin-page. It is based on django-filter. It provides a flexible and direct way to filter the items of your changelist and to save and reuse your queries.
Installation
Install from pypi.org:
pip install django-admin-filter
Setup
There are a few things you need to do to use a custom filter-form for your model in your admin changelist:
Add django_admin_filter to your INSTALLED_APPS:
INSTALLED_APPS = [ 'django_admin_filter', ... ]
Include the django_admin_filter.urls into your project urlpatterns. The django_admin_filter.urls must precede the admin.site.urls:
urlpatterns = [
path('admin/', include('django_admin_filter.urls')),
path('admin/', admin.site.urls),
...
]
Add the CustomFilter to the list_filter of your ModelAdmin:
from django_admin_filter.filters import CustomFilter class MyAdmin(admin.ModelAdmin): list_filter = [CustomFilter, ...] ...
And setup the filter-class you want to use with your model. This works exactly as described in the django-filter-docs. But to use your filter-class with the django-admin-filter there is one thing to mind: Instead of subclass django_filters.FilterSet:
import django_filters class MyFilter(django_filters.FilterSet): ...
use the AdminFilterSet:
from django_admin_filter.filterset import AdminFilterSet class MyFilter(AdminFilterSet): ...
Configuration
django_admin_filter defines some settings by its own. These settings and their default values are:
ADMIN_FILTER_HISTORY_LIMIT = 3 ADMIN_FILTER_TRUNCATE_HISTORY = True ADMIN_FILTER_URL_PATH = 'filter/'
ADMIN_FILTER_HISTORY_LIMIT
Filter queries that are not saved but only applied will be kept in the history section of the custom filter. The HISTORY_LIMIT setting defines how many applied filter queries will be kept. If you do not want to have a history of your applied queries at all set this setting to 0.
ADMIN_FILTER_TRUNCATE_HISTORY
By default applied filters that are beyond the scope of the filter history will be delete automatically from the database. Set this setting to False if you want to keep them for any reason.
ADMIN_FILTER_URL_PATH
By default the route for the filter query form will be composed as follows:
<app-label>/<model>/filter/[<pk>]
If this does not work with your project you can alter the “filter/” part by using the ADMIN_FILTER_URL_PATH setting.
Usage
The CustomFilter will show up on the right with all the other list filters. It allows you to create new queries - based on your AdminFilterSet - or apply existing queries - either recent ones from the history, or those you created. It is also possible to create globel filter queries that can be used by every user. To do so a user must have an extra permission defined with the FilterQuery model:
"Can handle global FilterQueries"
Users with this permission can commonly create edit and delete global filters.
Metadata
Release files for django-admin-filter 0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-admin-filter-0.7.tar.gz | 15.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_admin_filter-0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.7 kB
Release files / django-admin-filter-0.7.tar.gz
| Download URL | django-admin-filter-0.7.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b85f783d80b322979ccc8de7ca254584954f3acf72a7e0a75eaa5d7c92b613a1
|
|
BLAKE2b-256 checksum How to use checksums |
66d54553047d7d63c162aaa3e7323accf35b892ea15fbe95b314b9e5bc080a50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3
|
Release files / django_admin_filter-0.7-py3-none-any.whl
| Download URL | django_admin_filter-0.7-py3-none-any.whl |
|---|---|
| Size | 24.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f3818e2a80a30b29046a1dc27476197f8ba5352dcf6830045cc715f8d1edfa76
|
|
BLAKE2b-256 checksum How to use checksums |
e96916a86d585d6880c5570b5e82d36a933a5f1f2fdc60f15eacd9a7abd5e47c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.25.1 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3
|