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.
Run python manage.py collectstatic to install the dynfilters media.
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', '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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4e3e6084d1bc1b1f19fc5a1491cecf2598cf3213c3a075af58b47fda6ef5fdb |
|
MD5 | da6e653419a5d4370e13d2e2537736ce |
|
BLAKE2b-256 | 4f94e9bdb22b31fbb7269be4a4aee47445b696b068b8d5a9eace903de96b89e8 |
Hashes for django_dynamic_filters-2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c32f1d25c1199cdf21a5c07a1b10236e0304b7df87b2946c45f9841ad84194a |
|
MD5 | a071eb2d43512eec3bc9ec1a356c3485 |
|
BLAKE2b-256 | ef3695771ce9ce4fd91bceaca14bf250899dba717d307eafbe26b2ab755170f0 |