Skip to main content

Adds support for writable nested serializers to the Django REST framework.

Project description

DRF Nested Serializer

Adds support for writable nested serializers to the Django REST framework.

Find out more with the Getting Started guide.

Features

  • All relationship types
    • Including through model
  • Drop-in replacement
  • Create and update support
  • Flexible field in- and exclusion

Example

from rest_framework.serializers import ModelSerializer
from drf_nested_serializer.serializer import NestedModelSerializer
from .models import MyChildModel, MyParentModel

class MyChildSerializer(ModelSerializer):
    class Meta:
        model = MyChildModel
        fields = ("id", "")

class MyParentSerializer(NestedModelSerializer):
    nested = MyChildSerializer()

    class Meta:
        model = MyParentModel
        fields = ("id", "nested")
data = {
    "child": {
        "name": "John Doe"
    }
}
serializer = MyParentSerializer(data=data)
if serializer.is_valid():
    instance = serializer.save()
print(MyParentSerializer(instance=instance).data)
{
    "id": 1,
    "child": {
        "id": 1,
        "name": "John Doe"
    }
}

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

drf_nested_model_serializer-0.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

drf_nested_model_serializer-0.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file drf_nested_model_serializer-0.0.1.tar.gz.

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 65d09ae4b32b2feeb2b7763bbbfdb0fbc4e9ab316b6de45fa60fde11ef5b46fb
MD5 86a362f5c61cb6e51f4eca149ed3cc5d
BLAKE2b-256 5955a5ab19046b653a6724a456d8c04c21384a815307ddc974c2b1c08d6ff37e

See more details on using hashes here.

File details

Details for the file drf_nested_model_serializer-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30f47eca02af9095a506e9c2b702d067d2d1b8a522438122e8c1865df3fda33e
MD5 4800288e359b1790034baa71e0e82461
BLAKE2b-256 0a4cc4548bb255e7a1c7f3bfbcd4bc94b5208f6ff62cdbe203b5a1cd79263785

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