Skip to main content

Construct arbitrarily complex Django "Q" filters from flat data, such

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_filternaut-1.0.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_filternaut-1.0.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file django_filternaut-1.0.0.tar.gz.

File metadata

  • Download URL: django_filternaut-1.0.0.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

Hashes for django_filternaut-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c60af39004741bbbf75b93ed6cd89245ac4f4a3fcecfe4cb1ccd651ca693215b
MD5 b54eddf8eafb7a25c1429ce23b6d0ffb
BLAKE2b-256 52b690379e90ccfc8b0145701f5893c5bae593e9444aa4a493fd04703dd16b91

See more details on using hashes here.

File details

Details for the file django_filternaut-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_filternaut-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff02421b46fb76c88e39a449e9d642853768bb641ba93ef6bafe661966096074
MD5 6ea05c4ead4f158a4cbf512704d43ca4
BLAKE2b-256 fb51534fc9231dc09b76d9390d67d5c7f82b910a294d4be80395e914f601dfff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page