Skip to main content

DRF multiple serializer

Build Status

Extension for using multiple serializer in Django REST Framework.

Installation

Install from PyPI

pip install drf-multiple-serializer

There is no need to modify your INSTALLED_APPS setting.

Usage

Action Base

Set the serializer to serializer_classes with the viewset action.
The rest of the actions use the default serializer.

from rest_framework import viewsets
from drf_multiple_serializer import MultipleSerializerMixin


class CategoryViewSet(ActionBaseSerializerMixin,
                      viewsets.ModelViewSet):
    queryset = Category.objects.all()
    serializer_classes = {
        'default': CategorySerializer,
        'list': CategoryListSerializer,
        'retrieve': CategoryReadSerializer,
    }

Read & Write

Set the read & write serializer to serializer_classes.
List, Retrieve actions use a read serializer,
and the other actions (include delete) use a write serializer.

from rest_framework import viewsets
from drf_multiple_serializer import ReadWriteSerializerMixin


class ItemViewSet(ReadWriteSerializerMixin,
                  viewsets.ModelViewSet):
    queryset = Item.objects.all()
    serializer_classes = {
        'read': ItemReadSerializer,
        'write': ItemWriteSerializer,
    }

Test

> python3 -m venv venv
> source venv/bin/activate
(venv) > pytest

Metadata

Release files for drf-multiple-serializer 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-multiple-serializer 0.2.3
File Size Uploaded Provenance Actions
drf-multiple-serializer-0.2.3.tar.gz 3.1 kB Without provenance Details for drf-multiple-serializer-0.2.3.tar.gz

Release files / drf-multiple-serializer-0.2.3.tar.gz

Download URL drf-multiple-serializer-0.2.3.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1919c7c3d55959971cdd53f68b9fc695c4d58733bf5a0f935a4b565ce88b54d8
BLAKE2b-256 checksum
How to use checksums
2ab0741bf0b9d789621c6808ad9b2213a162cd3764f26d8082d1f1b8df7b7da2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.6.8

Security for drf-multiple-serializer 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page