| 61 | Update a model instance. |
| 62 | """ |
| 63 | def update(self, request, *args, **kwargs): |
| 64 | partial = kwargs.pop('partial', False) |
| 65 | instance = self.get_object() |
| 66 | serializer = self.get_serializer(instance, data=request.data, partial=partial) |
| 67 | serializer.is_valid(raise_exception=True) |
| 68 | self.perform_update(serializer) |
| 69 | |
| 70 | if getattr(instance, '_prefetched_objects_cache', None): |
| 71 | # If 'prefetch_related' has been applied to a queryset, we need to |
| 72 | # forcibly invalidate the prefetch cache on the instance. |
| 73 | instance._prefetched_objects_cache = {} |
| 74 | |
| 75 | return Response(serializer.data) |
| 76 | |
| 77 | def perform_update(self, serializer): |
| 78 | serializer.save() |