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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.5.tar.gz
Algorithm Hash digest
SHA256 a61d5643b85a89088a7224a8050ae35563b87f080fdee97b096605991959b3a7
MD5 2ac98d28c5dd3c171137d66def2f75d9
BLAKE2b-256 621437b9641de48729728a0ba524362b4aff650c35d718b576f4a0ec8d21e873

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e87eead7ca48c4dda4d0829290d29a0e028a0ff3c59f343014695500694ec33b
MD5 fa13d29b9917399d64d5815f7d4265db
BLAKE2b-256 df1bfcadb515bd6bb53a6f0ccc4fe4b2b93797ca44e5228d15b6fdc15a4094a6

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