54.Django(장고) - ecommerce 프로젝트 - 주문목록

JungSik Heo·2024년 12월 14일

1. 주문록록을 navbar.html 에 추가

          <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
            <li>
              <a class="dropdown-item" href="{% url 'payment:payment_update_info' %}">주문목록</a>
            </li>
            <li>

2. urls.py에 추가

    path("payment_order_list/", views.payment_order_list, name="payment_order_list"), #dev_45 추가

3. views.py에 추가

def payment_order_list(request):

    if request.user.is_authenticated:
        
        #Get Current uer's shipping Info
        orders = Order.objects.filter(user__id=request.user.id)
                
        return render(request, "payment/payment_order_list.html",{'orders':orders})
    else:
         messages.success(request, "You Must be logged In To Access That Page!!")
         return redirect('/login')

4. templates\payment\payment_order_list.html 추가

{% comment %} #dev_45 추가{% endcomment %}
{% load static %}
{% comment %} #dev_42 {% endcomment %}
{% block content %}

  {% include 'store/head.html' %}
  <div class="d-flex flex-column vh-100 justify-content-between">

    <!-- 네비게이션바 -->
    {% include "layout/navbar.html" %}

    <header class="bg-dark py-5">
      <div class="container px-4 px-lg-5 my-5">
        <div class="text-center text-white">
          <h1 class="display-4 fw-bolder">주문목록</h1>
          <p class="lead fw-normal text-white-50 mb-0">your orders are..</p>
        </div>
      </div>
    </header>

    <br/>

    <div class="container my-5">
      <h1 class="text-center"><strong>주문 목록</strong></h1>
      <br>
      <br>
      <table class = "table table-dark text-center">
        <thead class = "thead thead-dark">
            <tr>
                <td scope = "col">주문번호</td>
                <td scope = "col">상품명</td>
                <td scope = "col">수량</td>
                <td scope = "col">주문날짜</td>
            </tr>
        </thead>
        <tbody class = "text-light">           
            {% for order in orders %}
              {% for item in order.orderitem_set.all %}
                <tr>
                  <td scope = "col">{{order.id}}</td>
                  <td>{{item.product}}</td>
                  <td>{{item.quantity}}개</td>
                  <td>{{order.updated_at|date:'Y-m-d H:i'}}</td>
                </tr> 
              {% endfor %} 
            {% endfor %}
        </tbody>
    </table>

    </div>

    <!-- Footer-->
    {% include 'store/footer.html' %}
  </div>
{%endblock content%}

아래과 같이 나오는가 확인

profile
쿵스보이(얼짱뮤지션)

0개의 댓글