github
📝버스예매
날짜선택후 예매 또는 취소
1. 날짜선택할 html
✍ 날짜 선택할 html 생성
<body>
<div class="regibox" align="center">
<form method="POST" action="select_date">
{% csrf_token %}
<input type="date" id="date" name="date" value="2021-02-20" min="2021-02-20" max="2022-01-01">
<br><br>
<button type="submit" value="submit">예매할 날짜 선택</button>
</form>
</div>
<br><br>
<div class="regibox" align="center">
<form method="POST" action="cancel_date">
{% csrf_token %}
<input type="date" id="date" name="date" value="2021-02-20" min="2021-02-20" max="2022-01-01">
<br><br>
<button type="submit" value="submit">취소할 날짜 선택</button>
</form>
</div>
</body>
✍ 날짜 선택할 html 띄우는 함수
def date(request):
return render(request,'date.html')
2. 예매할 html띄우기
✍ 예매할 날짜 선택후 html 띄우는 함수
def select_date(request):
#폼 입력값 가져오기
date=request.POST['date']
if Bus.objects.filter(date__contains='{}'.format(date)).count()>0:
date=request.POST['date']
chk_list = []
i=1
while i<10:
bus_number=get_object_or_404(Bus, number=i, date=date)
if bus_number.check==1:
chk_list.append("disabled")
if bus_number.check!=1:
chk_list.append("")
i=i+1
return render(request,'seat.html',{'list':chk_list, 'date':date})
else:
i=1
while i<10:
bus=Bus()
bus.number=i
bus.check=0
bus.date=date
bus.save()
i=i+1
return render(request,'seat.html',{'date':date})
3. 취소할 html띄우기
✍ 취소할 날짜 선택후 html 띄우는 함수
def cancel_date(request):
#폼 입력값 가져오기
date=request.POST['date']
chk_list = []
i=1
while i<10:
bus_number=get_object_or_404(Bus, number=i, date=date)
if bus_number.check==1:
chk_list.append("")
if bus_number.check!=1:
chk_list.append("disabled")
i=i+1
return render(request,'seat_cancel.html',{'list':chk_list, 'date':date})