Skip to main content

Handle multiple serializers for the same view in Django Rest Framework.

Project description

drf-multi-serializers

Handle multiple serializers for the same view in Django Rest Framework.

Installation

pip install drf-multi-serializers

Usage

Simply import the MultiSerializerMixin and use it in your API views:

from rest_framework.generics import ListCreateAPIView
from rest_framework.viewsets import ModelViewSet
from drf_multi_serializers import MultiSerializerMixin

...

class MyAPIView(MultiSerializerMixin, ListCreateAPIView):
    ...
    serializer_classes = {
        "create": MyCreateSerializer,
        "list": MyListSerializer,
    }
    ...

class MyViewSet(MultiSerializerMixin, ModelViewSet):
    ...
    serializer_classes = {
        "create": MyCreateSerializer,
        "list": MyListSerializer,
        "metadata": MyMetadataSerializer,  # create ViewSets require either serializer_class or metadata serializer for OPTION requests
        "partial_update": MyUpdateSerializer,
        "retrieve": MyRetrieveSerializer,
        "update": MyUpdateSerializer,
    }
    ...

Contributing

Contributions are welcome! To get started, please refer to our contribution guidelines.

Issues

If you encounter any problems while using this package, please open a new issue here.

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_multi_serializers-1.1.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

drf_multi_serializers-1.1.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file drf_multi_serializers-1.1.1.tar.gz.

File metadata

  • Download URL: drf_multi_serializers-1.1.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.6

File hashes

Hashes for drf_multi_serializers-1.1.1.tar.gz
Algorithm Hash digest
SHA256 6e6553b765fda545070c0056932fea483e9a05dda7661f7fe019b7f9bb842dda
MD5 2b332d7806e6ff3dceda17811c38fcb2
BLAKE2b-256 3be8aac1fce0e0b56f3752d3461e17c5692968d852f2e65bd0b8a60858bf00ec

See more details on using hashes here.

File details

Details for the file drf_multi_serializers-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for drf_multi_serializers-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3acd82df4b34ce322caf13f6963216556a47c329f91b6dfa4d930e6042ae47aa
MD5 6785195f40dafc149c16b8d58180bf90
BLAKE2b-256 9366c2c615931b63d1935f6b143bb4dd78a565d4ef5450b1a9c74937a7c70b82

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page