Django-버스예매_좌석

mseo39·2021년 2월 5일
0

toyproject

목록 보기
6/8
post-thumbnail

github

📝버스예매

개인프로젝트입니다

좌석 페이지

1. 자리예매할 html띄우기

✍ 자리예매할 html 생성
    <div class="plane">
        <div class="cockpit">
            <h1>Please select a seat</h1>
        </div>
      
        <form action="chk" method="post">
            {% csrf_token %}
            <ol class="cabin fuselage">
                <li class="row row--1">
                    <ol class="seats">
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="1" value="1" {{list.0}} />
                            <label for="1">1</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="2" value="2" {{list.1}}/>
                            <label for="2">2</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="3" value="3" {{list.2}}/>
                            <label for="3">3</label>
                        </li>
                    </ol>
                </li>
                <li class="row row--2">
                    <ol class="seats">
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="4" value="4" {{list.3}}/>
                            <label for="4">4</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="5" value="5" {{list.4}}/>
                            <label for="5">5</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="6" value="6" {{list.5}}/>
                            <label for="6">6</label>
                        </li>
                    </ol>
                </li>
                <li class="row row--3">
                    <ol class="seats">
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="7" value="7" {{list.6}}/>
                            <label for="7">7</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="8" value="8" {{list.7}}/>
                            <label for="8">8</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="9" value="9" {{list.8}}/>
                            <label for="9">9</label>
                        </li>
                    </ol>
                </li>


            </ol>
            <button type="submit" value="submit">예매하기</button>
        </form>
       
    </div>
    
✍ html을 띄어줄 함수
def seat(request):

    chk_list = []
    i=1
    while i<10:
        bus_number=get_object_or_404(Bus, number=i)
        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})

자리취소

1. 자리취소할 html띄우기

✍ 자리취소할 html 생성
     <div class="plane">
        <div class="cockpit">
            <h1>Please select a seat</h1>
        </div>
      
        <form action="chk_cancel" method="post">
            {% csrf_token %}
            <ol class="cabin fuselage">
                <li class="row row--1">
                    <ol class="seats">
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="1" value="1" {{list.0}} />
                            <label for="1">1</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="2" value="2" {{list.1}}/>
                            <label for="2">2</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="3" value="3" {{list.2}}/>
                            <label for="3">3</label>
                        </li>
                    </ol>
                </li>
                <li class="row row--2">
                    <ol class="seats">
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="4" value="4" {{list.3}}/>
                            <label for="4">4</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="5" value="5" {{list.4}}/>
                            <label for="5">5</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="6" value="6" {{list.5}}/>
                            <label for="6">6</label>
                        </li>
                    </ol>
                </li>
                <li class="row row--3">
                    <ol class="seats">
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="7" value="7" {{list.6}}/>
                            <label for="7">7</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="8" value="8" {{list.7}}/>
                            <label for="8">8</label>
                        </li>
                        <li class="seat">
                            <input type="checkbox" name="answer[]" id="9" value="9" {{list.8}}/>
                            <label for="9">9</label>
                        </li>
                    </ol>
                </li>


            </ol>
            <input type="hidden" id="date" name="date" value={{date}}>
            <button type="submit" value="submit">취소하기</button>
        </form>
       
    </div>
    
✍ html을 띄어줄 함수
def seat_cancel(request):

    chk_list = []
    i=1
    while i<10:
         bus_number=get_object_or_404(Bus, number=i)
         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})
profile
하루하루 성실하게

0개의 댓글