mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
Reintroduce save hooks
This commit is contained in:
parent
6bfed6f852
commit
3fa4a1898a
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user