Reintroduce save hooks

This commit is contained in:
Tom Christie 2014-10-07 17:21:12 +01:00
parent 6bfed6f852
commit 3fa4a1898a

View File

@ -20,10 +20,13 @@ class CreateModelMixin(object):
def create(self, request, *args, **kwargs):
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
serializer.save()
self.create_valid(serializer)
headers = self.get_success_headers(serializer.data)
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
def create_valid(self, serializer):
serializer.save()
def get_success_headers(self, data):
try:
return {'Location': data[api_settings.URL_FIELD_NAME]}
@ -64,9 +67,12 @@ class UpdateModelMixin(object):
instance = self.get_object()
serializer = self.get_serializer(instance, data=request.data, partial=partial)
serializer.is_valid(raise_exception=True)
serializer.save()
self.update_valid(serializer)
return Response(serializer.data)
def update_valid(self, serializer):
serializer.save()
def partial_update(self, request, *args, **kwargs):
kwargs['partial'] = True
return self.update(request, *args, **kwargs)