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_model_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.4.tar.gz (4.7 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.4-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.4.tar.gz
Algorithm Hash digest
SHA256 313513d1cba482026c3ef6cf011b4232e92fdf1a094f9e41fb889f9d0ca7db10
MD5 5c91bd98768d411420d4a02ff8c46ce1
BLAKE2b-256 f02cb71cbd01e2339b6439b428b7807d4be84c5c6dc432588343a28520529477

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 99c6e7ed4180eb2f9b191b6c4da898e5956ffac1a3992b84500802fb0592fa76
MD5 1ed05ba77721bdca1ab132bf7199db13
BLAKE2b-256 cd7c61995325510f0c1974f0eda0ead6378bc8c5fef592e3d0ce1bdf1f6b0272

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