Skip to main content

A Django application for dynamic admin filters.

Project description

Package License Downloads Python Django

A django ModelAdmin Filter which adds advanced filtering abilities to the admin.

creating filters

Creating a filter

using filters

Apply a filter

Requirements

Installation & Set up

  1. Run pip install django-dynamic-filters to install dynfilters.

  2. Add “dynfilters” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'adminsortable2',
        'dynfilters',
    ]
  3. Add “dynfilters” URL to your urls.py file:

    urlpatterns = [
        ...
        path('dynfilters/', include('dynfilters.urls')),
    ]
  4. Run python manage.py migrate to create the dynfilters models.

  5. 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'),
]

Sharing

There are two ways dynamic filters can be shared:

  1. By marking a filter global. The filter will be available to all admin users.

  2. By pressing the share icon. The filter can then be shared by email. When the recipients clicks on the received link, a copy of the filter will be created. The edits made to the copy will not affect the original filter.

Alternatives

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-dynamic-filters-2.4.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_dynamic_filters-2.4-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file django-dynamic-filters-2.4.tar.gz.

File metadata

  • Download URL: django-dynamic-filters-2.4.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for django-dynamic-filters-2.4.tar.gz
Algorithm Hash digest
SHA256 d4e3e6084d1bc1b1f19fc5a1491cecf2598cf3213c3a075af58b47fda6ef5fdb
MD5 da6e653419a5d4370e13d2e2537736ce
BLAKE2b-256 4f94e9bdb22b31fbb7269be4a4aee47445b696b068b8d5a9eace903de96b89e8

See more details on using hashes here.

File details

Details for the file django_dynamic_filters-2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dynamic_filters-2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9c32f1d25c1199cdf21a5c07a1b10236e0304b7df87b2946c45f9841ad84194a
MD5 a071eb2d43512eec3bc9ec1a356c3485
BLAKE2b-256 ef3695771ce9ce4fd91bceaca14bf250899dba717d307eafbe26b2ab755170f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page