|
楼主 |
发表于 2021-9-13 14:57:13
|
显示全部楼层
本帖最后由 niceyes 于 2021-9-13 15:02 编辑
def search_result(request):
#定义空字典-------------------------------------------
result_list=[]
if request.method=='GET':
return render(request,'search_result.html')
elif request.method=='POST':
project_name=request.POST['project_name']
print(project_name)
search_project=ProjectInfo.objects.filter(project_name__contains=project_name)
for project_name_c in search_project:
project_id=project_name_c.id
search_order=OrderTicket.objects.filter(id_project=project_id)
for order_id_c in search_order:
order_id=order_id_c.id
search_rebar=Rebar.objects.filter(id_orderticket=order_id)
for rebar_id_c in search_rebar:
#把查询结果生成字典
result_dict={'sample_id':rebar_id_c.id,
'order_id':order_id_c.id,
'project_id':project_name_c.id,
'project_name':project_name_c.project_name,
'sample_name':order_id_c.sample_name,
'sample_type':rebar_id_c.model_diameter,
'order_date':order_id_c.order_date,
'position':rebar_id_c.position,
'test_date':rebar_id_c.test_end_date,
}
#把字典加入列表,然后在网页模板上遍历生成表
result_list.append(result_dict)
print(result_list)
return render(request,'search_result.html',locals())
我后面想了一个办法,把查询结果生成 列表, 但是还是不行, 首先, 日期字段 返回一个 'order_date': datetime.date(2020, 12, 30), 这个在列表中没引号,语法就不对
另外, 网页模板 遍历list表时出错 |
|