Skip to main content
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.

Release files for django-filtrate 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-filtrate 0.1.1
File Size Uploaded
django-filtrate-0.1.1.tar.gz 7.6 kB Details

Release files / django-filtrate-0.1.1.tar.gz

Download URL django-filtrate-0.1.1.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dd42d8a07c13ae4e4dd3a3bcaf0b9e11b88d7f5e2c6518cefc6726e89d985a8a
BLAKE2b-256 checksum
How to use checksums
3f4bd39de6611a07f921e11eecbaa12f0b57d85132fc895014de3a1423ef246e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page