Skip to content

Declaring resource actions

Any methods on the resource viewset decorated with @action(detail=True, methods=['post']) will be recognized as resource actions. For example:

1
2
3
4
5
6
7
8
9
class InstanceViewSet(structure_views.BaseResourceViewSet):

    @action(detail=True, methods=['post'])
    def start(self, request, uuid=None):
        pass

    @action(detail=True, methods=['post'])
    def unlink(self, request, uuid=None):
        pass

Complex actions and serializers

If your action uses serializer to parse complex data, you should declare action-specific serializers on the resource viewset. For example:

1
2
3
4
class InstanceViewSet(structure_views.BaseResourceViewSet):

    assign_floating_ip_serializer_class = serializers.AssignFloatingIpSerializer
    resize_serializer_class = serializers.InstanceResizeSerializer