0

I'm working on a small project using Django and VueJS, i would like todo a bulk delete, i'm sending an array object of my IDs, using Axios in the body like that : [1,2,3]

this is my code :

getAPI({
   method: 'DELETE',
   url: 'api/contact/delete/',
   data:{
     ids: this.selected
   }
 }).then((response) => {
    console.log(response.data)
 })

how can i loop over my ids in django this is my function :

@action(methods=['delete'], detail=False)
def delete(self, request):
    for i in request.body:
        print(request[i])
  • Does this answer your question? [How to receive json data using HTTP POST request in Django 1.6?](https://stackoverflow.com/questions/24068576/how-to-receive-json-data-using-http-post-request-in-django-1-6) – Ivan Starostin Mar 23 '21 at 19:04

1 Answers1

0

It looks like someone else had a similar question here: Delete multiple objects in django

Essentially, you can pass the list of IDs to your delete view and use a queryset within that view to get the list of model instances you want to delete. Your queryset should be something like this:

MyModel.objects.filter(id__in=(your_id_list)).delete()
brandonris1
  • 445
  • 3
  • 9