Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. Exception Type: ProtectedError at /api/v1/spi/sites/6
  2. Exception Value: ("Cannot delete some instances of model 'Site' because they are referenced through a protected foreign key: 'Location.site'", <QuerySet [<Location: a_location>]>)
  3.  
  4. class LocationDetail(generics.RetrieveUpdateDestroyAPIView):
  5. # using get_queryset().order_by('id') prevents UnorderedObjectListWarning
  6. queryset = Location.objects.order_by('id')
  7. serializer_class = LocationSerializer
  8. permission_classes = (SPIPermission,)
  9.  
  10. def perform_destroy(self, instance):
  11. print('LocationDetail destroy() called.')
  12. location = self.get_object().location
  13. try:
  14. location.delete()
  15. except Exception as ex:
  16. print(ex)
  17. return Response({"message": "%s." % ex}, status=status.HTTP_400_BAD_REQUEST)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement