Hi,
I’ve just started learning to create Django Rest APIs. I have a model containing data, and I’m using the django-filters library to add URL filtering. My test views are implemented as:
class SiteList(generics.ListCreateAPIView):
queryset = Site.objects.all()
serializer_class = SiteSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = ['client',]
class SiteDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Site.objects.all()
serializer_class = SiteSerializer
I want to be able send a DELETE on 127.0.0.1:8000/api/clients/sites?client=2 that would result in all sites with a client id of 2 being deleted. The filterset_fields will expand in the future, trying to keep everything as simple as possible.
I understand ListCreateAPIView doesn’t allow DELETE requests but I have no idea how to go about changing things to work with the django-filters library. I know I could send delete requests from the front-end (react) individually for each item I want deleted but this feels really inefficient.
Thanks!