1024programmer Java Django batch delete

Django batch delete

I haven’t used it for a long time. Let’s sort it out today

Batch deletion can be done through a list passed from the front desk.

We use __in to determine whether the elements in the list are in this model

Backend code

class DelAPIView(APIView):
     def post(self, request):
         del_list = request.data.get(\'del_list\') #  Get the list passed from the front desk
         BooksModel.objects.filter(id__in = del_list).delete() #Use id__in to get the data and then delete it

         return Response({\'code\':200,\'msg\':\'okokokok\'})

Front-end code

<tr v-for="book in book_list" >
           <td><input type="checkbox" :value="book.id" v-model="del_" ><  /td> //This is a multi-select box v-model bound to a list :value is bound to the id of each piece of data
             <td><img :src="_self.$  host + \'/\' +book.image" alt="This is a picture" width="  50px" height="50px"></td>

To be continued. . . . .

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/756932

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us


Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top