Skip to main content

Customizable Django Admin filters

Project description

https://img.shields.io/badge/license-BSD-blue.svg https://img.shields.io/pypi/v/django-filtrate.svg https://img.shields.io/pypi/pyversions/django-filtrate https://img.shields.io/badge/code%20style-black-000000.svg

Allow trusted users to create custom Django admin filters

Quickstart

Install Django Filtrate:

pip install django-filtrate

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    "filtrate",
    ...
)
  1. Add the mixin

class YourModelAdmin(FiltrateMixin, admin.ModelAdmin):
    ...
  1. Navigate to http://localhost:8000/admin/filtrate/filter

  2. Add your new filter!

How it works

As soon as you add the FiltrateMixin to your ModelAdmin, your model and admin will be registered with Filtrate. At this point, you can navigate to the Filtrate admin page, and begin adding filters.

Filtrate uses Django’s built-in filtering to build it’s ListFilters, by passing the filters field as arguments to the queryset. See https://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-specific-objects-with-filters for more details about filtering queries with Django.

For example, let’s say you have the following Template model:

class Template(models.Model):
    name = models.CharField(max_length=25)
    is_active = models.BooleanField(default=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.name

If you wanted to build a filter for all active Templates created on or after 2023-01-01, then your Filter.filters should look like:

{
    "is_active": True,
    "created_at__gte": "2023-01-01",
}

Save it, and then voila, you have a new filter on your TemplateAdmin!

Happy Filtering!

Features

  • Filter data model

  • FiltrateMixin ModelAdmin mixin

TODO’s

  • User-specific filters

  • Export data

  • Add Filter button on changelist

  • Additional test coverage

  • Setup tox

  • More documentation

Local Development

make install
make test

Deployment

make build
make deploy

License

This project is provided under the BSD License.

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-filtrate-0.1.1.tar.gz (7.6 kB view details)

Uploaded Source

File details

Details for the file django-filtrate-0.1.1.tar.gz.

File metadata

  • Download URL: django-filtrate-0.1.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.9

File hashes

Hashes for django-filtrate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dd42d8a07c13ae4e4dd3a3bcaf0b9e11b88d7f5e2c6518cefc6726e89d985a8a
MD5 8c46414194fb93ddd8d47b0f1a60e224
BLAKE2b-256 3f4bd39de6611a07f921e11eecbaa12f0b57d85132fc895014de3a1423ef246e

See more details on using hashes here.

Supported by

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