当我点击模板中的django视图中的某个按钮时,如何从查询集中执行对象删除
这是我的代码......
views.py
def CamerasList(request):
model = Cameras
# This function can hadle both the retrieval of the view, as well as the submission of the form on the view.
if request.method == 'POST':
form = CamerasForm(request.POST, request.FILES)
if form.is_valid():
form.delete_cam_id = request.POST.get('delete_cam_id')
deletelement = Cameras.objects.get(pk=form.delete_cam_id)
deletelement.delete()
var = {}
var = user_group_validation(request)
theuser = request.user
theuserid = Users.objects.get(user_id=theuser.id).pk
theorgid = Users.objects.get(pk=theuserid).organization_id.pk
if var['grupo'] == 'superuser':
object_list = Cameras.objects.all()
organization = Organizations.objects.all()
url = request.session['url']
if var['grupo'] == 'admin' or var['grupo'] == 'user':
object_list = Cameras.objects.filter(organization_id=request.session['userInc'])
organization = Organizations.objects.filter(id=request.session['userInc'])
url = request.session['url']
template = get_template(app+u'/cameras_list.html')
return HttpResponse(template.render(locals()))