3

Suppose I create this viewset:

class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    lookup_field = 'username'

and this router:

router.register(r'users', views.UserViewSet)

and this serializer:

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ('username', 'password', 'email')

Is there documentation that mentions if, by default, it does or does not allow user accept PUT, PARTIAL_UPDATE, DELETE, LIST and CREATE requests?

SilentDev
  • 20,997
  • 28
  • 111
  • 214

1 Answers1

3

The mapping is explained in the router's documentation

Linovia
  • 19,812
  • 4
  • 47
  • 48
  • 1
    Thanks. Is there a way to make it so that the Viewset does not accept put or destroy requests? (My current way of doing it is creating a permissions `NoPut` and `NoDestroy` which returns `False` if the action is `put`or `destroy`. – SilentDev Mar 05 '17 at 22:10
  • 1
    Yup, you need to herit from GenericViewSet and add the mixin you want to implement (mixins.CreateModelMixin, mixins.RetrieveModelMixin, mixins.ListModelMixin) – Linovia Mar 05 '17 at 23:59