freshcrate
Home > Frameworks > django-filter

django-filter

Django-filter is a reusable Django application for allowing users to filter querysets dynamically.

Description

Django Filter ============= Django-filter is a reusable Django application allowing users to declaratively add dynamic ``QuerySet`` filtering from URL parameters. Full documentation on `read the docs`_. .. image:: https://raw.githubusercontent.com/carltongibson/django-filter/python-coverage-comment-action-data/badge.svg :target: https://github.com/carltongibson/django-filter/tree/python-coverage-comment-action-data .. image:: https://badge.fury.io/py/django-filter.svg :target: http://badge.fury.io/py/django-filter Versioning and stability policy ------------------------------- Django-Filter is a mature and stable package. It uses a two-part CalVer versioning scheme, such as ``21.1``. The first number is the year. The second is the release number within that year. On an on-going basis, Django-Filter aims to support all current Django versions, the matching current Python versions, and the latest version of Django REST Framework. Please see: * `Status of supported Python versions <https://devguide.python.org/versions/#supported-versions>`_ * `List of supported Django versions <https://www.djangoproject.com/download/#supported-versions>`_ Support for Python and Django versions will be dropped when they reach end-of-life. Support for Python versions will be dropped when they reach end-of-life, even when still supported by a current version of Django. Other breaking changes are rare. Where required, every effort will be made to apply a "Year plus two" deprecation period. For example, a change initially introduced in ``23.x`` would offer a fallback where feasible and finally be removed in ``25.1``. Where fallbacks are not feasible, breaking changes without deprecation will be called out in the release notes. Installation ------------ Install using pip: .. code-block:: sh pip install django-filter Then add ``'django_filters'`` to your ``INSTALLED_APPS``. .. code-block:: python INSTALLED_APPS = [ ... 'django_filters', ] Usage ----- Django-filter can be used for generating interfaces similar to the Django admin's ``list_filter`` interface. It has an API very similar to Django's ``ModelForms``. For example, if you had a Product model you could have a filterset for it with the code: .. code-block:: python import django_filters class ProductFilter(django_filters.FilterSet): class Meta: model = Product fields = ['name', 'price', 'manufacturer'] And then in your view you could do: .. code-block:: python def product_list(request): filter = ProductFilter(request.GET, queryset=Product.objects.all()) return render(request, 'my_app/template.html', {'filter': filter}) Usage with Django REST Framework -------------------------------- Django-filter provides a custom ``FilterSet`` and filter backend for use with Django REST Framework. To use this adjust your import to use ``django_filters.rest_framework.FilterSet``. .. code-block:: python from django_filters import rest_framework as filters class ProductFilter(filters.FilterSet): class Meta: model = Product fields = ('category', 'in_stock') For more details see the `DRF integration docs`_. Support ------- If you need help you can start a `discussion`_. For commercial support, please `contact Carlton Gibson via his website <https://noumenal.es/>`_. .. _`discussion`: https://github.com/carltongibson/django-filter/discussions .. _`read the docs`: https://django-filter.readthedocs.io/en/main/ .. _`DRF integration docs`: https://django-filter.readthedocs.io/en/stable/guide/rest_framework.html

Release History

VersionChangesUrgencyDate
25.2Imported from PyPI (25.2)Low4/21/2026
23.1Release 23.1Low4/23/2023
22.1Release 22.1Low7/26/2022
21.1Release 21.1Low9/26/2021
2.4.0* SECURITY: Added a ``MaxValueValidator`` to the form field for ``NumberFilter``. This prevents a potential DoS attack if numbers with very large exponents were subsequently converted to integers. The default limit value for the validator is ``1e50``. The new ``NumberFilter.get_max_validator()`` allows customising the used validator, and may return ``None`` to disable the validation entirely. * Added testing against Django 3.1 and Python 3.9. In addition tests against Low9/27/2020
2.3.0https://github.com/carltongibson/django-filter/blob/master/CHANGES.rst#version-230-2020-6-5Low6/5/2020
2.2.0Highlights: * Added ``DjangoFilterBackend.get_schema_operation_parameters()`` for DRF 3.10+ OpenAPI schema generation. (#1086) * Added ``lookup_expr`` to ``MultipleChoiceFilter`` (#1054) * Dropped support for EOL Python 3.4 Low7/16/2019
2.1.0* Fixed a regression in `FilterView` introduced in 2.0. An empty `QuerySet` was incorrectly used whenever the `FilterSet` was unbound (i.e. when there were no `GET` parameters). The correct, pre-2.0 behaviour is now restored. A workaround was to set `strict=False` on the `FilterSet`. This is no longer necessary, so you may restore `strict` behaviour as desired. * Added `IsoDateTimeFromToRangeFilter`. Allows From-To filtering using ISO-8601 formatted dates.Low1/20/2019
2.0.02.0 introduced a number of small changes and tidy-ups. Please see the migration guide: https://django-filter.readthedocs.io/en/master/guide/migration.html#migrating-to-2-0 * Added testing for Python 3.7 (#944) * Improve exception message for invalid filter result (#943) * Test QueryDict against CSV filters (#937) * Add `renderer` argument to `render()` method of `BooleanWidget` (#923) * Fix lookups for reverse relationships (#915) * Refactor backend filterset instantiation (#865) * Low7/13/2018
1.1.0* Add Deprecations for 2.0 (#792) * Improve IsoDateTimeField test clarity (#790) * Fix form attr references in tests (#789) * Simplify tox config, drop python 3.3 & django 1.8 (#787) * Make get_filter_name a classmethod, allowing it to be overriden for each FilterClass (#775) * Support active timezone (#750) * Docs Typo: django_filters -> filters in docs (#773) * Add Polish translations for some messages (#771) * Remove support for Django 1.9 (EOL) (#752) * Use required attribute from fLow10/19/2017
1.0.4Quick fix for verbose_field_name issue (#722)Low5/19/2017
1.0.3Improves compatibility with Django REST Framework schema generation. See the [1.0.3 Milestone](https://github.com/carltongibson/django-filter/milestone/13?closed=1) for full details. Low5/16/2017
1.0.2Updates for compatibility with Django 1.11 and Django REST Framework 3.6. Adds CI testing against Python 3.6 See the [1.0.2 Milestone](https://github.com/carltongibson/django-filter/milestone/12?closed=1) for full details. Low3/24/2017
1.0.1Small patch. Assuming DRF is installed, adds `rest_framework` submodule to the `django_filters` namespace. This allows usage like: ``` import django_filters class ProductFilter(django_filters.rest_framework.FilterSet): # .... ``` without requiring a further import. Low11/28/2016
1.0.0This release removes all the deprecated code from 0.14 and 0.15 for 1.0 #480. Please see the [Migration Notes](https://github.com/carltongibson/django-filter/blob/1.0.0/docs/guide/migration.txt) for details of how to migrate. Stick with 0.15.3 and fix warnings there if you're not ready to update. The release also includes a number of small fixes and documentation updates. See the [1.0 Milestone](https://github.com/carltongibson/django-filter/milestone/8?closed=1) for full details. Low11/17/2016
0.15.3Adds compatibility for DRF (3.5+) get_schema_fields filter backend introspection. Low10/17/2016
0.15.2Quick fix for #506. Removes an import time dependency on having the Django Template Language backend configured. Low9/29/2016
0.15.1A couple of quick bug fixes: - #496 OrderingFilter not working with Select widget - #498 DRF Backend Templates not loading Recommended. Low9/28/2016
0.15.0This is a preparatory release for a 1.0. Lots of clean-up, lots of changes, mostly backwards compatible. Special thanks to Ryan P Kilby (@rpkilby) for lots of hard work. Most changes should raise a Deprecation Warning. **Note**: if you're doing _Clever Thingsβ„’_ with the various filter options β€”Β `filter_overrides` etc β€”Β you may run into an `AttributeError` since these are now defined on the metaclass and not on the filter itself. (See the discussion on #459) Summary: Highly Recommended, but tLow9/20/2016
0.14.0Small release adding a number of fixes and a `DurationFilter`. [See the Milestone for Full Details](https://github.com/carltongibson/django-filter/milestone/6?closed=1) Low8/14/2016
v0.13Lots of good stuff. [See the milestone](https://github.com/carltongibson/django-filter/issues?q=milestone%3A0.13) Low3/11/2016
0.12.0Improves compatibility with Django 1.8 and 1.9, adds a JavaScript friendly `BooleanWidget` and support for custom ORM lookup types. Full changes: https://github.com/alex/django-filter/compare/0.11.0...0.12.0 Recommended. Low1/7/2016
0.11.0Lots of cool things: - Added default filter method lookup for MethodFilter #222 - Added support for yesterday in daterangefilter #234 - Created Filter for NumericRange. #236 - Added Date/time range filters #215 - Added option to raise with `strict` #255 - Added Form Field and Filter to parse ISO-8601 timestamps #264 Enjoy Low8/14/2015
v0.10.0Fixes a `ForeignObjectRel` change with Django 1.8. Smuggles in a couple of little feature additions. Low5/13/2015

Dependencies & License Audit

Loading dependencies...

Similar Packages

pre-commitA framework for managing and maintaining multi-language pre-commit hooks.v4.6.0
azure-core-tracing-opentelemetryMicrosoft Azure Azure Core OpenTelemetry plugin Library for Pythonazure-template_0.1.0b6187637
spdx-toolsSPDX parser and tools.0.8.5
lacesDjango components that know how to render themselves.0.1.2
django-tasksA backport of Django's built in Tasks framework0.12.0