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.mixins 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.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

drf_multi_serializers-1.0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: drf_multi_serializers-1.0.1.tar.gz
  • Upload date:
  • Size: 2.8 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.1.tar.gz
Algorithm Hash digest
SHA256 8db29b12110b1a71b79d7fb396d167613ac6e202934b19b71da5108ca10eccd7
MD5 09f722626bc9559ad31e11f25184bea4
BLAKE2b-256 fa068beb756ffeee65365d5eb500bf6fd6bed2c735349a46e47b2f6b5a7e0bf1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for drf_multi_serializers-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9325c08041fd025435563e5915ec66556f3d96ce8cacc664aa035bc154c64fbc
MD5 1794ecfc62645a04f6f06b6ac626cace
BLAKE2b-256 7920582997e9cef00068b2b503393a178fa8b3593587384722693202ca1110cc

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