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"
    }
}

Build and publish

Increase version number in pyproject.toml.

stubgen -m drf_nested_model_serializer -o drf_nested_model_serializer
py -m build
py -m twine upload dist/*

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.8.tar.gz (4.8 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.8-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.8.tar.gz
Algorithm Hash digest
SHA256 3b227672c9e7683832516a51b98f99e381a912fc9ea48553fb0dbe94927a6cb1
MD5 d0ca5808f0095cba092237768c4162df
BLAKE2b-256 bdead4a940591cc739f8dfe7b056039e6e2976e3485b7f49ff29567a0c0f0b45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 4b185c3e897556d4939ee12873cb5661d391921f1039f896f86e9a01f53be57a
MD5 f1eb108fc3e7f82788d3775cf9df6a5f
BLAKE2b-256 c517685b3c83ffb22dff6bcf55835c608565425686942109b9349d24a5614e99

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