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. For example, if you have an API listing and want to let the requester filter that listing with query params, Filternaut is the ticket.
Using Filternaut, you put together filters of different types — e.g. a date filter and an email filter — and say what their logical relationships are.
Quickstart
# first define how you will parse the incoming filters choices.
filters = (
DateTimeFilter('created_date', lookups=['lt', 'gt']) &
CharFilter('username', lookups=['icontains'])
)
# then use this to parse anything dict-like. This returns a Django
# Q-object for use with the ORM's .filter().
try:
query = filters.parse(request.GET)
return queryset.filter(query)
except filternaut.InvalidData as ex:
raise HttpResponseBadRequest(ex.errors)
Installation
$ pip install django-filternaut
Filternaut is compatible with:
Python 3
Django 4.2 and 5.0
Django REST Framework 3.15 (optional)
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
File details
Details for the file django_filternaut-1.0.1.tar.gz
.
File metadata
- Download URL: django_filternaut-1.0.1.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3314248774e85869ae3999bf26f82be4ba2c80e62506efa797d7f037db419ff8 |
|
MD5 | b29ca0bcc497a88cec6d3606d9a6a1ce |
|
BLAKE2b-256 | 5f98f1eee9c9ebe0da1f89f63df5a8a904cc9f3cbce4850b8bbb6a4770eed8c4 |
File details
Details for the file django_filternaut-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_filternaut-1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aab070357476fd5a413e125a1ed2b096ba9ca39a59281adb444444a2fbfc9fe |
|
MD5 | 6a4739c68a5ff7a1dffd7ceb602eff7b |
|
BLAKE2b-256 | 0dbde0e571deb6896bd3197ea418a458d692691897440414a5b0696287d794fb |