def search_accomodation(request): if request.method == "POST": id = request.POST.get("id", None) roomid = Accommodation.objects.filter(顾客id=id) print(roomid) room_id_set = [] time = None for f in roomid: id = f.客房编号.房间号 room_id_set.append(id) time = f.入住时间 print(room_id_set) room_list = [] for room_id in room_id_set: room = Room.objects.get(房间号=room_id) num = room.房间号 type = room.客房类型 price = room.价格 li = { "房间号": num, "客房类型": type, "价格": price, "入住时间": time } room_list.append(li) print(room_list) return render(request, 'accomodation.html', {"room_list": room_list})
时间: 2024-04-09 11:32:09 浏览: 45
Accomodation_App:住宿申请
这段代码是一个搜索住宿信息的函数。它接收一个请求对象作为参数,在POST请求方法中,从请求中获取顾客id,并根据id过滤出相关的住宿记录。然后,将房间号和入住时间存储在room_id_set和time变量中。接下来,通过遍历room_id_set,查询每个房间的详细信息,并将房间号、客房类型、价格和入住时间存储在room_list列表中。最后,将room_list作为参数传递给渲染模板,返回渲染结果。
请问有什么我可以帮助您的吗?
阅读全文