Skip to main content

A simple package to handle multiple serializers for the same ViewSet in Django Rest Framework

Project description

drf-multi-serializers

A simple package to 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.0.2.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for drf_multi_serializers-1.0.2.tar.gz
Algorithm Hash digest
SHA256 44d60c9af849134ea76bd9d427c7b813d6faa97e6da5feb85da1f4f3073e7d10
MD5 e47f0db663484b2888c71115669854b1
BLAKE2b-256 a42688a0db2dfdae77cc0d7253f8277cfcf76726977d01319869b17fa5b68f60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_multi_serializers-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 51c3a9873014125b661a1d17e5135e9c143d91dcb758f2084a16b44177181a85
MD5 990f0f21d6b424ebfe5a3145cafc469e
BLAKE2b-256 09a67fd32baab2add163dccf3a3e0325b741bee08333e7dc59468821dd95a1a0

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