5

I'm using viewsets that has several actions (retrieve, list, create etc...). I also use swagger to get a clean overview of my API. The problem is that it's full of unused method (PATCH, PUT, DELETE) and it messes up the view.

I've tried to do this in my viewsets : allowed_methods = ('GET','POST',)

The swagger still has all these unused method. How can I change this behavior ? Is there another way to limit the number of actions in a viewset ? Or maybe the problem is on swagger side ?

0

1 Answer 1

10

You need to compose your viewset view more accurately to get rid of them.

Default ModelViewSet is:

class ModelViewSet(
        mixins.CreateModelMixin,
        mixins.RetrieveModelMixin,
        mixins.UpdateModelMixin,
        mixins.DestroyModelMixin,
        mixins.ListModelMixin,
        GenericViewSet):
    pass

Therefore if you just want say the list and create methods, it'll be:

class MyViewSet(
        mixins.CreateModelMixin,
        mixins.ListModelMixin,
        GenericViewSet):
    serializer_class = ....
    queryset = ....
Sign up to request clarification or add additional context in comments.

1 Comment

Note that if you need to limit requests to just GET, there is the ReadOnlyModelViewSet() method under the ViewSet class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.