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 hashes)

Uploaded Source

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