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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.6.tar.gz
Algorithm Hash digest
SHA256 93fd63bcab33794c114805ebce1a643fa43da8f5ce8d3f735736369702c34894
MD5 c97b6e5159170aa724223c15b4ae9f02
BLAKE2b-256 0169c53f98a6754373e0cd76a2211a68a34d9ddbe60016dd8339acb48dc85ead

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2103b847dc5b911989e006c62e14123eea3e9fd037c20e9a184337ee384499ef
MD5 47028379267b3a02bd483111f799f103
BLAKE2b-256 46b0edd1b02033125bef4c4f27622ce135b19cbee7461770e5f4f3cf23f51ab4

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