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",
...
)
Add the mixin
class YourModelAdmin(FiltrateMixin, admin.ModelAdmin):
...
Navigate to http://localhost:8000/admin/filtrate/filter
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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-filtrate-0.1.1.tar.gz | 7.6 kB | Without provenance | Details for django-filtrate-0.1.1.tar.gz |
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
|
Security for django-filtrate 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.