class UpdateModelMixin
from rest_framework.mixins import UpdateModelMixin
Documentation
Source code
Update a model instance.
Ancestors (MRO)
- UpdateModelMixin
Methods used but not implemented in this class
- get_object
- get_serializer
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)
if getattr(instance, '_prefetched_objects_cache', None):
# If 'prefetch_related' has been applied to a queryset, we need to
# forcibly invalidate the prefetch cache on the instance.
instance._prefetched_objects_cache = {}
return Response(serializer.data)