django中批量刪除資料的方法
阿新 • • 發佈:2018-12-25
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')