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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.9.tar.gz
Algorithm Hash digest
SHA256 53078ea2b6aeb988c9e6c800e113d95db6afb9a157b7b9537cf3b6e487c88f95
MD5 3c0f58fce4df79aca1beacf648665e4b
BLAKE2b-256 5790b8bd9de83c98c524d3e0b04f22e6b0929224294c2e88fa2c771346e0f630

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 bbe62f028c7db5e840fcf094bc35784b927be83ebcfa59bf28cf5e07c56cbf1b
MD5 32d99bb1fd388d2d7cbbaf4c65cb837a
BLAKE2b-256 314e3a9611068dd351c80ceb725e4fe3200a3c6077c1404ce172fb87c32899d9

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