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.0.1.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djangorestframework_inclusions-1.0.1-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: djangorestframework-inclusions-1.0.1.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.9

File hashes

Hashes for djangorestframework-inclusions-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d9b35eeaf62c27e4770e5060d452166e1556d44621464cd76a4651c9e2e4d0a8
MD5 faede46fff306844365502d599f27820
BLAKE2b-256 707e77b4e991d362d76b14a6da6e215fdf8f42cb1971c927916d8d2a2e67e1ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: djangorestframework_inclusions-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.9

File hashes

Hashes for djangorestframework_inclusions-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3da739e5c65bd3374424b289f54a1cdd6bbbf23bc61ea602dbaaed67054f9cc6
MD5 deb1facd3be575082d666554e050861c
BLAKE2b-256 6923a49feae008a81dcb697f583a1cb7abc9ca8ab21b08f9afb3ca05c796bf73

See more details on using hashes here.

Supported by

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