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.1.0.tar.gz (14.4 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.1.0-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: djangorestframework-inclusions-1.1.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for djangorestframework-inclusions-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ea93ad849f5c200774679ca6a271d508109195c763e7d199f42218b191391163
MD5 06bf1f99b5b638f26390a9ad812e5aab
BLAKE2b-256 3f5c55c0d0451034dcb844fdb8fad121bfab13257de7841e300cac26dfa916fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: djangorestframework_inclusions-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for djangorestframework_inclusions-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92edbd75899f7d524687dadd06b712b07c4df7b67b63319518cfdf439a079a3d
MD5 e99da2fe4cedc1f25d167bbaf39b9606
BLAKE2b-256 9bcfbf0ae5fc1d02a7050de729e9c104e9189732fc7f2e2e6d076d768dc4f118

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