A DRF renderer to side-load relations
Project description
DRF-inclusions
A django-restframework renderer to side-load related resources.
One drawback of RESTful APIs is that you have to make many calls to fetch all the related resources. DRF-inclusions provides a custom renderer allowing you to sideload those in a single, original request.
DRF-inclusions allows you to specify which serializers to use for included resources, and via the query string the client can specify which resources should be included.
Features:
- arbitrary depth
- option to include all related resources
- de-duplication when the same object is found in multiple parent/related objects
- an effort is made to retrieve related objects in as little DB queries as possible
Installation
pip install djangorestframework-inclusions
Usage
from rest_framework_inclusions.renderer import InclusionJSONRenderer
class MySerializer(...):
inclusion_serializers = {"some_field": OtherSerializer}
class MyViewSet(...):
...
renderer_classes = (InclusionJSONRenderer,)
See the tests
and testapp
for advanced usage examples.
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
File details
Details for the file djangorestframework-inclusions-1.2.0.tar.gz
.
File metadata
- Download URL: djangorestframework-inclusions-1.2.0.tar.gz
- Upload date:
- Size: 16.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 085249de77bafd861aa07152bdc8ddb431bb1cec9738d5b58f0894ba3c5aef5d |
|
MD5 | 680c9469da76f51715937b1351983c1b |
|
BLAKE2b-256 | 44393f48cea275b3bb06735e2e18a706fa0a33dc43f9ec0b5bdda62312635807 |
File details
Details for the file djangorestframework_inclusions-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: djangorestframework_inclusions-1.2.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f925a96c686b7afee1593a0b162d35f58aef0fa8c6ca0826e84d9a194438f89f |
|
MD5 | bf0943fe1b63a826b6cdf4c27b228b64 |
|
BLAKE2b-256 | 658e822c0ff232e0251b92b578329770c598aae25a57f6fa64c0325caa326424 |