Construct arbitrarily complex Django "Q" filters from flat data, such as query parameters.
Project description
Filternaut is a simple library which generates arbitrarily complex Django Q-objects from simple data. It fits nicely into situations where users provide data which you want to filter a queryset with.
Filternaut is indirectly a collection of fields, but it differs from Django forms in that you specify the logical relationships between fields, as well their names and types.
Filternaut is similar to Django Filters, but does not provide any machinery for rendering a user interface and does not inspect your models to autogenerate filters. However, Django Filters chains many calls to .filter() which means OR-like behaviour with more than one join. Filternaut supports either behaviour.
Quickstart
# filters are combined using logical operators
filters = (
DateTimeFilter('created_date', lookups=['lt', 'gt']) &
CharFilter('username', lookups=['icontains']))
# they can read their values from anything dict-like
filters.parse(request.GET)
# and have a form-like 'validity pattern'.
if filters.valid:
queryset = queryset.filter(filters.Q)
else:
raise HttpResponseBadRequest(json.dumps(filters.errors))
Installation
$ pip install django-filternaut
Filternaut is compatible with:
Python 3
Django 2.2 and 3.0
Django REST Framework 3.11 (optional)
Python 2.7 support is still in the codebase but no longer tested. You are welcome to try your luck.
Documentation
See https://filternaut.readthedocs.org for full documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_filternaut-0.0.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ddfcc0992325116ace0ec4a54bd8cc03b8c26677b4061b080d1391c32a2f51d |
|
MD5 | d6d6f90cd3f0aac1f0ef00eca377c195 |
|
BLAKE2b-256 | c8910e11833c2031ccc3bfa116069658f34bb4ff57021c2517797150589ed69b |