当前,我正在尝试使用ajax post方法更新表中的某些字段,如果ajax [data]!='None',则给出了一个条件,然后更新了一个字段。仅当条件有一个语句(如果我通过另一个语句)时,它才起作用,它仅更新该字段,而不是更新查询中提到的所有内容。
def outwardmailupdateMaker(request):
datetime = 'None'
if request.is_ajax() and request.method == "POST":
out_id = request.POST['out_id']
senders_details = request.POST['senders_details']
mail_particulars = request.POST['mail_particulars']
address = request.POST['address']
sender_remarks = request.POST['remarks']
pod_number = request.POST['pod_number']
if pod_number != 'None':
bm_pod_confirmation = 'Updated'
else:
bm_pod_confirmation = 'Pending'
OutwardMailTable.objects.filter(pk=out_id).update(senders_details=senders_details,
mail_particulars=mail_particulars,
address=address,
sender_remarks=sender_remarks,
pod_number=pod_number,
bm_pod_confirmation=bm_pod_confirmation)
return HttpResponse("test")
这将更新传递给update方法的所有字段,但是下面仅在pod_number!='None'
时更新pod_uploaded_date字段。def outwardmailupdateMaker(request):
datetime = 'None'
if request.is_ajax() and request.method == "POST":
out_id = request.POST['out_id']
senders_details = request.POST['senders_details']
mail_particulars = request.POST['mail_particulars']
address = request.POST['address']
sender_remarks = request.POST['remarks']
pod_number = request.POST['pod_number']
if pod_number != 'None':
bm_pod_confirmation = 'Updated'
pod_uploaded_date = now
else:
bm_pod_confirmation = 'Pending'
OutwardMailTable.objects.filter(pk=out_id).update(senders_details=senders_details,
mail_particulars=mail_particulars,
address=address,
sender_remarks=sender_remarks,
pod_number=pod_number,
pod_uploaded_date=pod_uploaded_date,
bm_pod_confirmation=bm_pod_confirmation)
return HttpResponse("test")