A Django application for dynamic admin filters.
Project description
A django ModelAdmin Filter which adds advanced filtering abilities to the admin.
creating filters
using filters
Requirements
Django >= 4.0 on Python 3.9+/PyPy3
Installation & Set up
Run pip install django-dynamic-filters to install dynfilters.
Add “dynfilters” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'adminsortable2', 'dynfilters', ]
Add “dynfilters” URL to your urls.py file:
urlpatterns = [ ... path('dynfilters/', include('dynfilters.urls')), ]
Run python manage.py migrate to create the dynfilters models.
Integration Example
models.py
class Address(models.Model):
town = models.CharField(max_length=32)
class Person(models.Model):
first_name = models.CharField(max_length=32)
last_name = models.CharField(max_length=32)
birth_date = models.DateField()
address = models.ForeignKey(Address, on_delete=models.CASCADE)
admin.py
from dynfilters.filters import DynamicFilter
@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
...
list_filter = (DynamicFilter,)
dynfilters_fields = [
'-',
'first_name',
'last_name',
'first_name|last_name', # Will generate Q(first_name=<value>) | Q(last_name=<value>)
('birth_date', 'Date of birth'), # Requires the value to be: DD/MM/YYYY
'-',
('address__town', 'City'),
]
dynfilters_select_related = ['address'] # Optional
dynfilters_prefetch_related = [] # Optional
Operators & Lookups
The following operators and lookups are supported:
operators
OP_CHOICES = [
('-', '-'),
('!', 'NOT'),
('&', 'AND'),
('|', 'OR'),
('(', '('),
(')', ')'),
]
lookups
LOOKUP_CHOICES = [
('-', '---------'),
('=', 'Equals'),
('icontains', 'Contains'),
('istartswith', 'Starts with'),
('iendswith', 'Ends with'),
('in', 'One of'), # Requires the value to be: aaa,bbb,ccc
('-', '---------'),
('range', 'Date Range'), # Requires the value to be: DD/MM/YYYY,DD/MM/YYYY
('year', 'Date Year'),
('month', 'Date Month'),
('day', 'Date Day'),
('-', '---------'),
('isnull', 'Is NULL'),
('isnotnull', 'Is not NULL'),
('istrue', 'Is TRUE'),
('isfalse', 'Is FALSE'),
('-', '---------'),
('lt', 'Less Than'),
('gt', 'Greater Than'),
('lte', 'Less Than or Equal To'),
('gte', 'Greater Than or Equal To'),
]
Alternatives
Dynfilters was inspired by the look and feel of django-advanced-filters, but is based purely on admin forms and inlines (no JSON).
Another interesting package is django-filter.
And yet another one is django-admin-search-builder.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-dynamic-filters-2.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 225aa11f8f150f32155fa03eb11f4648840ba6b53b7aa66251a4676b939c7e97 |
|
MD5 | bb9d03962ceadbe962ddb136a09b7924 |
|
BLAKE2b-256 | 2b0a68b53eec9f9cdbce06afc0a8e5c16d6f048aa4dd1725af8e061fcb4dc750 |
Hashes for django_dynamic_filters-2.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1f2e33f2099f8d5e567cbd04f55958f7eafcb56fd87006fa0a9269a0f02231d |
|
MD5 | ef506a47d1a957c394cffc8ee6c8dc59 |
|
BLAKE2b-256 | 61690aba281256ea5dc112be39103f2f02caa9ed1da04c1286a9e32a64d9bff0 |