Groups
Groups

Django Rest Framework Custom Viewsets.

89 views
Skip to first unread message

Malik Junaid

unread,
Jun 24, 2016, 6:57:39 AM6/24/16
to Django users

A very small library for extending the functionality of DRF ModelViewSet.

Viewsets

The first of out custom viewsets is the CustomSerializerViewSet that allows you to specify different serializers for different actions of a viewset.

Quickstart

Install Rest Framework Custom ViewSets:

pip install rest_framework_custom_viewsets

then extend you ViewSet class from viewsets.CustomSerializerViewSet

Example:

from drf_custom_viewsets.viewsets.CustomSerializerViewSet
from myapp.serializers import DefaltSerializer, CustomSerializer1, CustomSerializer2

class MyViewSet(CustomSerializerViewSet):
    serializer_class = DefaultSerializer
    custom_serializer_classes = {
        'create':  CustomSerializer1,
        'update': CustomSerializer2,
    }

Tom Christie

unread,
Jun 24, 2016, 8:38:05 AM6/24/16
to Django users
Good stuff - make sure to add it to the django packages grid, here: https://www.djangopackages.com/grids/g/django-rest-framework/

You could also create a docs pull request to add a "Third Party Packages" to the viewsets section, here: http://www.django-rest-framework.org/api-guide/viewsets/#viewsets

Reply all
Reply to author
Forward
0 new messages
Search
Clear search
Close search
Google apps
Main menu