class UpdateModelMixin

from rest_framework.mixins import UpdateModelMixin
Documentation Source code
    Update a model instance.
    

Ancestors (MRO)

  1. UpdateModelMixin

Methods used but not implemented in this class

  • get_object
  • get_serializer
Expand Collapse

Methods

def partial_update(self, request, *args, **kwargs): UpdateModelMixin

    def partial_update(self, request, *args, **kwargs):
        kwargs['partial'] = True
        return self.update(request, *args, **kwargs)

def perform_update(self, serializer): UpdateModelMixin

    def perform_update(self, serializer):
        serializer.save()

def update(self, request, *args, **kwargs): UpdateModelMixin

    def update(self, request, *args, **kwargs):
        partial = kwargs.pop('partial', False)
        instance = self.get_object()
        serializer = self.get_serializer(instance, data=request.data, partial=partial)
        serializer.is_valid(raise_exception=True)
        self.perform_update(serializer)
        return Response(serializer.data)