# dj-rest-filters
dj-rest-filters is a Django application allowing users to declaratively add dynamic QuerySet filtering from URL parameters. Its uses Django Rest Framework serializers in backend so it provides same syntax as of serializers. You can validate you query parameter in same way as you validate in your serializer and it also provides filtering mechanism against custom query parameters.
[![Build](https://github.com/mhsiddiqui/dj-rest-filters/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/mhsiddiqui/dj-rest-filters/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/mhsiddiqui/dj-rest-filters/branch/master/graph/badge.svg?token=IBWACI93GM)](https://codecov.io/gh/mhsiddiqui/dj-rest-filters) [![Docs](https://readthedocs.org/projects/dj-rest-filters/badge/?version=latest)](https://dj-rest-filters.readthedocs.io/en/latest/?badge=latest)
## Installation
> pip install dj-rest-filters
Then add 'djfilters' to your INSTALLED_APPS.
## Usage
### Filtering
```python
from rest_framework import generics
from djfilters.backend import DjFilterBackend
class TodoView(generics.GenericAPIView):
serializer_class = ...
filter_class = TodoFilter
filter_backends = [DjFilterBackend]
queryset = Todo.objects.all()
```
### Validation Only
When queryset is declared, filter will be used to filter that queryset. But when there is not any queryset, filter will just be used to validate the provided query parameters.
```python
from rest_framework import generics
class TodoView(generics.GenericAPIView):
serializer_class = ...
filter_class = MyFilter
```
### Filter Context
Just like serializer context, context can be passed to filter by using `get_filter_context` function like this.
```python
from rest_framework import generics
class TodoView(generics.GenericAPIView):
....
def get_filter_context(self):
context = {'extra_data': 'some_extra_data'}
return context
```
### Accessing Validated Query Params
After query param validation, validated parameters can be accessed using `request.cleaned_args`.
For detailed documentation, click [here](https://dj-rest-filters.readthedocs.io/en/latest/).
Raw data
{
"_id": null,
"home_page": "https://github.com/mhsiddiqui/dj-rest-filters",
"name": "dj-rest-filters",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": "",
"keywords": "django,filters,filter-backend,dj-rest-filters",
"author": "Muhammad Hassan Siddiqui",
"author_email": "mhassan.eeng@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/1d/95/5610f7eaf844bd177ffac641bf51ac30093e26ff9a866efd87969fe329e2/dj-rest-filters-1.0.4.tar.gz",
"platform": "any",
"description": "# dj-rest-filters\n\ndj-rest-filters is a Django application allowing users to declaratively add dynamic QuerySet filtering from URL parameters. Its uses Django Rest Framework serializers in backend so it provides same syntax as of serializers. You can validate you query parameter in same way as you validate in your serializer and it also provides filtering mechanism against custom query parameters.\n\n[![Build](https://github.com/mhsiddiqui/dj-rest-filters/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/mhsiddiqui/dj-rest-filters/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/mhsiddiqui/dj-rest-filters/branch/master/graph/badge.svg?token=IBWACI93GM)](https://codecov.io/gh/mhsiddiqui/dj-rest-filters) [![Docs](https://readthedocs.org/projects/dj-rest-filters/badge/?version=latest)](https://dj-rest-filters.readthedocs.io/en/latest/?badge=latest)\n\n\n## Installation\n\n> pip install dj-rest-filters\n\nThen add 'djfilters' to your INSTALLED_APPS.\n\n## Usage\n\n### Filtering\n```python\nfrom rest_framework import generics\nfrom djfilters.backend import DjFilterBackend\n\n\nclass TodoView(generics.GenericAPIView):\n serializer_class = ...\n filter_class = TodoFilter\n filter_backends = [DjFilterBackend]\n queryset = Todo.objects.all()\n```\n\n### Validation Only\nWhen queryset is declared, filter will be used to filter that queryset. But when there is not any queryset, filter will just be used to validate the provided query parameters.\n\n```python\nfrom rest_framework import generics\n\nclass TodoView(generics.GenericAPIView):\n serializer_class = ...\n filter_class = MyFilter\n```\n\n### Filter Context\nJust like serializer context, context can be passed to filter by using `get_filter_context` function like this.\n\n```python\nfrom rest_framework import generics\n\nclass TodoView(generics.GenericAPIView):\n ....\n\n def get_filter_context(self):\n context = {'extra_data': 'some_extra_data'}\n return context\n```\n\n### Accessing Validated Query Params\nAfter query param validation, validated parameters can be accessed using `request.cleaned_args`.\n\n\nFor detailed documentation, click [here](https://dj-rest-filters.readthedocs.io/en/latest/).\n\n\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django Rest Filter",
"version": "1.0.4",
"project_urls": {
"Homepage": "https://github.com/mhsiddiqui/dj-rest-filters"
},
"split_keywords": [
"django",
"filters",
"filter-backend",
"dj-rest-filters"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "30f2dfc5ab0dfc5924658ad380566db6ee0f7322194ef99472e8af7ab8b83d43",
"md5": "127f8a1d130bc7bfef2aac3a46228091",
"sha256": "05eb817d159d1207b6ed2d780d1e5b28d9bb9a2410bea0f721b0601849ef53c9"
},
"downloads": -1,
"filename": "dj_rest_filters-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "127f8a1d130bc7bfef2aac3a46228091",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 17642,
"upload_time": "2023-10-20T18:49:41",
"upload_time_iso_8601": "2023-10-20T18:49:41.171108Z",
"url": "https://files.pythonhosted.org/packages/30/f2/dfc5ab0dfc5924658ad380566db6ee0f7322194ef99472e8af7ab8b83d43/dj_rest_filters-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1d955610f7eaf844bd177ffac641bf51ac30093e26ff9a866efd87969fe329e2",
"md5": "8139642f3f0d4bd3342207f35d72bad7",
"sha256": "ef1f3dc1355313bf3046106e1cac633f10e27454e065f5d2dde477bde74a5a6c"
},
"downloads": -1,
"filename": "dj-rest-filters-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "8139642f3f0d4bd3342207f35d72bad7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 21309,
"upload_time": "2023-10-20T18:49:45",
"upload_time_iso_8601": "2023-10-20T18:49:45.407414Z",
"url": "https://files.pythonhosted.org/packages/1d/95/5610f7eaf844bd177ffac641bf51ac30093e26ff9a866efd87969fe329e2/dj-rest-filters-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-20 18:49:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mhsiddiqui",
"github_project": "dj-rest-filters",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "dj-rest-filters"
}