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

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.3.tar.gz (4.6 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.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f9229e73da572e11eedf32b5f318699ce14787156f7b7c82a0cfe9f38bc05dac
MD5 4aab988d525111231be2fb8700998f85
BLAKE2b-256 ae253a0759ed2bbfec0dc08a9fc7bb64bcc45862ccb2af07bd1be708416f5e63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_nested_model_serializer-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 eebe5857a97d70874d6281724a9b77c3cf44b36fda2b8cc6b32ce0e4114e74d0
MD5 2c2e62f281b57a1b031e97cb374ed122
BLAKE2b-256 48c1a91339c9a27d6f062616777ed149cf7ab455e3035357cce6988a6d0836cc

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