删除-----修改与删除等的操作,都从前台传来一个id获取后执行
class Delete_two_cate(View):
def get(self,request):
id = request.GET.get('id')
try:
two = Twocate.objects.filter(id=id).delete()
except:
two = {}
return redirect('/tnews_type')
# 二级分类批量删除
def Pop_two_cate(request):
try:
id = request.POST.getlist('ids')
except:
pass
Twocate.objects.filter(id__in=id).delete()
return redirect('/tnews_type')
注:批量删除必须要用getlist获取,相当于存入一个列表里面
批量删除的对应的前台在form表单中
1.action 提交的地址 <form action="/pop_cate/" method="POST">
2.input 框 例:<th width="10%"><input type='checkbox' name='ids' value="{{i.id}}">{{i.id}}</th>
3.button 按钮: <tr><td><button type='submit'>批量删除</button></td></tr>