mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 20:10:10 +03:00
Merge 3d54d4cd9a
into add1260be4
This commit is contained in:
commit
af9cd98d96
|
@ -7,6 +7,7 @@ which allows mixin classes to be composed in interesting ways.
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.db.models import ProtectedError
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
@ -191,6 +192,9 @@ class DestroyModelMixin(object):
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
obj = self.get_object()
|
obj = self.get_object()
|
||||||
self.pre_delete(obj)
|
self.pre_delete(obj)
|
||||||
obj.delete()
|
try:
|
||||||
|
obj.delete()
|
||||||
|
except ProtectedError:
|
||||||
|
return Response('Cannot delete object because of protected foreign key relation', status=status.HTTP_409_CONFLICT)
|
||||||
self.post_delete(obj)
|
self.post_delete(obj)
|
||||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user