欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

django中批量删除数据的方法

程序员文章站 2022-06-03 07:58:14
...
class TaskDeleteSelectView(View):
    def post(self, request):
        if not request.user.is_authenticated:
            # 判断用户登录状态
            return HttpResponse('{"status":"fail", "msg":"用户未登录"}', content_type='application/json')
        array = request.POST.getlist('ids')  # django接收数组
        idstring = ','.join(array)
        try:
            Tasklist.objects.extra(where=['id IN (' + idstring + ')']).delete()
        except:
            return HttpResponse('{"status":"fail", "msg":"ID不存在"}', content_type='application/json')
        return HttpResponse('{"status":"success", "msg":"操作成功"}', content_type='application/json')

https://blog.csdn.net/liangpz521/article/details/8108793