A Django app that provides tools for querying
Project description
Django Rest Framework Query Tools
This package facilitates filter operations via query parameters, simplifying the filtering process for Django Rest Framework views. Installation
Install via pip:
pip install django-rest-framework-query-tools
Usage Quick Example
Suppose you have a Books model with fields like author, title, etc. To filter Books by author using query params:
In your views.py, specify the field(s) to filter using filter_fields:
from rest_framework.views import APIView
from rest_framework import generics
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend
from drf_query_tools.filters import QueryParamsFilter
class BooksListView(generics.ListAPIView):
queryset = Books.objects.all()
serializer_class = BookSerializer
filter_backends = [QueryParamsFilter, DjangoFilterBackend]
filter_fields = ('author',)
Now, you can perform filtering by passing query parameters:
/v1/books?author=name
Integration Method 1: Integration in views.py
Import QueryParamsFilter and use it as a filter backend:
from drf_query_tools.filters import QueryParamsFilter
class BooksListView(generics.ListAPIView):
# ...
filter_backends = [QueryParamsFilter]
filter_fields = ('author',)
# ...
Method 2: Global Integration via settings.py
Add the QueryParamsFilter to your Django Rest Framework settings:
REST_FRAMEWORK = {
'DEFAULT_FILTER_BACKENDS': [
'drf_query_tools.filters.QueryParamsFilter'
]
}
Contributing
Feel free to contribute by opening issues or submitting pull requests! License
This project is licensed under the MIT License - see the LICENSE file for details
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_rest_framework_query_tools-0.0.14.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f0e985839ef526f0b8f18a9201145d9dfc4bdc353eed6bba344ff3783fa9917 |
|
MD5 | 83cd61f0eb044e889732a38f4f0d87ff |
|
BLAKE2b-256 | 99b140d40e14afbb12c8b53dc77fd3318850639d08aae6058e5f195e88c92263 |
Hashes for django_rest_framework_query_tools-0.0.14-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2893484690b42680eb79774ece82eb1c5858fb81fc5d3221d2590efaa317bdd7 |
|
MD5 | 6af81aa9e59b095059e02e897fc2fb25 |
|
BLAKE2b-256 | 53a8dad12941abfec341ebcab6770e5410816e2a92004179158304ef83b61ae8 |