The package allows developers to enhance filtering capabilities within Django Rest Framework views by simply specifying the desired filter fields. By incorporating the URLFilter into views or adding it to the Django Rest Framework settings, the package streamlines the filtering process.
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_rest_framework_query_tools.filters.url_fliter import URLFilter
class BooksListView(generics.ListAPIView):
queryset = Books.objects.all()
serializer_class = BookSerializer
filter_backends = [URLFilter]
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': [
'django_rest_framework_query_tools.filters.url_fliter.URLFilter'
]
}
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
File details
Details for the file django_rest_framework_query_tools-1.1.tar.gz
.
File metadata
- Download URL: django_rest_framework_query_tools-1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7dda73ad561ecb40af7d50ad957580d290524a53ebd5d5546e21c35b3d536949 |
|
MD5 | 6ec582dd31664d85e660b8cef014b1bb |
|
BLAKE2b-256 | 804c920d90cb4d9d7703f77f02576e2101ea271e44a1d35834a5d72385c91bab |
File details
Details for the file django_rest_framework_query_tools-1.1-py3-none-any.whl
.
File metadata
- Download URL: django_rest_framework_query_tools-1.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c4a703405c5cfdebe575a5e6721329d8937559ea2183cdcd5602ad5b1f3f998 |
|
MD5 | 64dba426d83b6769fe9e3b2c22a612a0 |
|
BLAKE2b-256 | c2ade5a6dfbe2ffa606a0bd058cf007a9d9c567ebbe3112e9e3c577b04a14d07 |