Skip to main content

A DRF renderer to side-load relations

Project description

DRF-inclusions

A django-restframework renderer to side-load related resources.

Build status Coverage status Python versions Django versions PyPI

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

djangorestframework-inclusions-1.2.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file djangorestframework-inclusions-1.2.0.tar.gz.

File metadata

File hashes

Hashes for djangorestframework-inclusions-1.2.0.tar.gz
Algorithm Hash digest
SHA256 085249de77bafd861aa07152bdc8ddb431bb1cec9738d5b58f0894ba3c5aef5d
MD5 680c9469da76f51715937b1351983c1b
BLAKE2b-256 44393f48cea275b3bb06735e2e18a706fa0a33dc43f9ec0b5bdda62312635807

See more details on using hashes here.

Provenance

File details

Details for the file djangorestframework_inclusions-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for djangorestframework_inclusions-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f925a96c686b7afee1593a0b162d35f58aef0fa8c6ca0826e84d9a194438f89f
MD5 bf0943fe1b63a826b6cdf4c27b228b64
BLAKE2b-256 658e822c0ff232e0251b92b578329770c598aae25a57f6fa64c0325caa326424

See more details on using hashes here.

Provenance

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