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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.7.tar.gz
Algorithm Hash digest
SHA256 f5342d6c426a62152dc5d310fca31ac64f387f5d2a62a350df40affb647e0588
MD5 af057f3d393ffd2427a80b791eb9d223
BLAKE2b-256 c5d60587480ae769f0be32a6e3f07878bcb027b8cf45c3c4ee49f64b60911c5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 85c315b147e576bca7a14223183966fcd37e53e90b4559e28d03ee04be5f0b9d
MD5 a088808ccae7dd1cb1b40152f11d2739
BLAKE2b-256 a1b47e934d59a407af9aa0749e9b0cbd378a5775c55cebbfd0f393e6e9caaade

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