django-minifilter
The django-minifilter package provides minimal filter functionality for list views, including:
-
a filter search box
-
filter links
The package is compatible with django's pagination.
Here's an example of a very basic list-view, showing a search box that filters by name, and links that filter by year and month:
Installation
The django-minifilter package is available on pypi and can be installed via pip:
pip install django-minifilter
or via pipenv:
pipenv install django-minifilter
Then add minifilter to INSTALLED_APPS in your django settings.
Quick example
Suppose we have the following simple model, part of an application called myapp:
from django.db import models
from django.utils import timezone
class MyModel(models.Model):
name = models.CharField(max_length=100)
date = models.DateField(default=timezone.now)
Here's how we would create a generic list view with a search box filter, links that filter by year and month, and pagination:
from django.views import generic
from minifilter.mixins import FilterMixin
from myapp.models import MyModel
class MyListView(FilterMixin, generic.ListView):
model = MyModel
template_name = 'myapp/mymodel_list.html'
paginate_by = 10
search_fields = ['name']
filter_parameters = [
# (url-parameter-name, lookup)
('year', 'start_date__year'),
('month', 'start_date__month'),
]
And here's a simple template for the above:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My filtered list view</title>
</head>
<body>
{% include 'minifilter/includes/search.html' %}
{% include 'minifilter/includes/parameters.html' %}
<div>
<ol>
{% for obj in page_obj %}
<li>{{ obj.name }} - {{ obj.date }}</li>
{% endfor %}
</ol>
</div>
{% include 'minifilter/includes/pagination.html' %}
</body>
</html>
Instead of a generic class-based view, we could also create a function-based list view:
from django.template.response import TemplateResponse
from django.core.paginator import Paginator
from minifilter.filters import search_filter, parameter_filter
from myapp.models import MyModel
def my_list_view(request):
queryset = MyModel.objects.all()
# filter by search term
queryset, search_form = search_filter(
queryset=queryset, request=request,
search_fields=['name'])
# filter queryset based on url query parameters
queryset, parameter_choices = parameter_filter(
queryset=queryset, request=request,
filter_parameters=[
('year', 'start_date__year'),
('month', 'start_date__month')])
# paginate filtered queryset
# see: https://docs.djangoproject.com/en/stable/topics/pagination/
paginator = Paginator(object_list=queryset, per_page=10)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
# build response
return TemplateResponse(
request, template='myapp/mymodel_list.html',
context=dict(
page_obj=page_obj,
parameter_choices=parameter_choices,
search_form=search_form,
)
)
Metadata
Release files for django-minifilter 0.0.5
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_minifilter-0.0.5.tar.gz | 7.6 kB | Without provenance | Details for django_minifilter-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_minifilter-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for django_minifilter-0.0.5-py3-none-any.whl |
Total release size: 16.9 kB
Release files / django_minifilter-0.0.5.tar.gz
| Download URL | django_minifilter-0.0.5.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ef9985107a618444ee4fe062aba4df34cb8ce561596583d738fd1931f772a9a
|
|
BLAKE2b-256 checksum How to use checksums |
06e61327e70ea591c0e9b1f21376d8edb572beac7732300de8f22412a2831fd2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.6
|
Release files / django_minifilter-0.0.5-py3-none-any.whl
| Download URL | django_minifilter-0.0.5-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c2fd4d9bd27ad6cb43742afb61f4a7834cf13fbd7b1601cba64548681de4587
|
|
BLAKE2b-256 checksum How to use checksums |
28f6b796fb282dd91e8b0322c2b6d6031ec1dc0b5346894d35301096e9bc38e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.6
|
Security for django-minifilter 0.0.5
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.