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.2.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.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ab521b737032941c3a01df8a711920cc3d13be8d585ba77cd86738fb77a00149
MD5 0591f52374010932b10e6ae05d802239
BLAKE2b-256 f7757b722546049d6355a46dee949978fefbef4f56f2708c2116f88f1ea681cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4a3ed7030c240acd4ec41d281a2cdc7ed94c6e9074c56a82ed83802cad46bc79
MD5 9be1a4617d348f17af0a357a2499fdcd
BLAKE2b-256 5547216b1891ac8a2f33c1f2d0017f8268f645d9927a3d0d0b8cd52bdd3f49b0

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