catch ForeignKey delete exception on city
This commit is contained in:
parent
dcf88408ae
commit
f16adb23f7
|
|
@ -1,5 +1,6 @@
|
||||||
"""Location app views."""
|
"""Location app views."""
|
||||||
from django.contrib.postgres.fields.jsonb import KeyTextTransform
|
from django.contrib.postgres.fields.jsonb import KeyTextTransform
|
||||||
|
from django.db.models.deletion import ProtectedError
|
||||||
from rest_framework import generics, status
|
from rest_framework import generics, status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
@ -167,6 +168,13 @@ class CityRUDView(common.CityViewMixin, generics.RetrieveUpdateDestroyAPIView):
|
||||||
IsGuest,
|
IsGuest,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def delete(self, request, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
return self.destroy(request, *args, **kwargs)
|
||||||
|
except ProtectedError:
|
||||||
|
from rest_framework.serializers import ValidationError
|
||||||
|
raise ValidationError({'detail': 'City couldn’t be deleted. Some objects has this city'})
|
||||||
|
|
||||||
|
|
||||||
# Region
|
# Region
|
||||||
class RegionListCreateView(common.RegionViewMixin, generics.ListCreateAPIView):
|
class RegionListCreateView(common.RegionViewMixin, generics.ListCreateAPIView):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user