This project provides some extra functionalities to be used with Django REST Framework
Project description
drf-addons-plus
Some magic to the base Django REST Framework
Overview
This project provides some extra functionalities to be used with Django REST Framework
- Field selection to Viewsets, eg.
?fields=id,name - Conditional filtering to Viewsets, eg.
?conditional=active,-inactive
Requirements
- Python 3.8+
- Django 4.2, 5.0, 5.1
- Django REST Framework 3.0+
or less, you can test it
Installation
Install using pip...
pip install drf_addons_plus
Examples
models.py:
from django.db import models
class FooModel(models.Model):
name = models.CharField(max_length=100)
status = models.BooleanField()
category = models.CharField(choices=['foo', 'bar'])
serializers.py:
from drf_addons_plus import serializers
from .models import FooModel
class FooSerializer(serializers.DynamicFieldsModelSerializer):
class Meta:
model = FooModel
fields = ['name', 'status', 'category']
views.py:
from rest_framework import filters
from drf_addons_plus import filters as filters_plus
from drf_addons_plus import viewsets
from .models import FooModel
from .serializers import FooSerializer
class FooViewSet(viewsets.FieldsModelViewSet):
queryset = FooModel.objects.all()
serializer_class = FooSerializer
permission_classes = []
filter_backends = [filters.SearchFilter, filters_plus.ConditionalFilter, filters_plus.FieldsFitlter]
search_fields = ['name']
conditional_fields = ['status']
filter_fields = ['category']
- Request
http://localhost:8000/foo/:
[
{
"name": "Bar",
"status": false,
"category": "Foo",
}
]
- Request
http://localhost:8000/foo/?fields=name&conditional=-status:
[
{
"name": "Bar"
}
]
- Request
http://localhost:8000/foo/?conditional=status:
[]
- Request
http://localhost:8000/foo/?category="foo":
[
{
"name": "Bar",
"status": false,
"category": "Foo",
}
]
Disclaimer
This project has started and maybe will be maintened, but it's simple enough to probably not give you any trouble.
Credits
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf_addons_plus-0.2.2.tar.gz.
File metadata
- Download URL: drf_addons_plus-0.2.2.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d678af7f044573f7fc0dca7cf622833f9be78ed5060c7c17ca82e33667d16cbe
|
|
| MD5 |
bdbc55c75f74959fe131b02ac81f9a41
|
|
| BLAKE2b-256 |
8fa7eb67f4909e4914a01a36ae64be8235ca1b66cc6aa89f5286de953aaf7c5c
|
File details
Details for the file drf_addons_plus-0.2.2-py3-none-any.whl.
File metadata
- Download URL: drf_addons_plus-0.2.2-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfa3ac433d7843ff8b33cf9194a979514d484a05b28166d3624d6cd22ad118dd
|
|
| MD5 |
dc071aa93cf0f1874928ed78479fddd8
|
|
| BLAKE2b-256 |
df94918195716e3a3cbf1aaaed633d1dd1a772c201a0800aa57a6db67a911c12
|