Skip to main content

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


Download files

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

Source Distribution

django_rest_framework_query_tools-1.1.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

Supported by

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