코딩공부/COVID-19-REPORT

COVID-19-REPORT . 04 - 리스트 가져오기

integerJI 2020. 8. 14. 07:30

COVID-19-REPORT (위치 기록 반응형 웹)

 

결과물

 

리스트 목록 페이지

  • 참고 : https://getbootstrap.com/docs/4.5/examples/cover/
  • 현재 사용자의 위치를 저장할 수 있는 페이지
  • 입력하기를 누를 경우 현재 위치의 위도와 경도값을 저장
  • input = text에는 위치의 간략한 설명을 적을 수 있으며 default는 Check

 

list.html

{% extends 'mainBase.html' %}
{% load static %}
{% block maincontent %}
<body class="text-center">
  <div class="cover-container d-flex w-100 h-100 p-3 mx-auto flex-column">
    <header class="masthead mb-auto">
      <div class="inner">
        <h3 class="masthead-brand"></h3>
        <nav class="nav nav-masthead justify-content-center">
          <a class="nav-link" href="{% url 'index' %}">Home</a>
          <a class="nav-link active" href="{% url 'list' %}">List</a>
          <a class="nav-link" href="{% url 'signout' %}">Sign out</a>
        </nav>
      </div>
    </header>
    <main role="main" class="inner cover">
      <h1 class="cover-heading">모든 경로</h1>
      <br>
      <table class="table">
        <thead>
          <tr>
            <th scope="col">위치</th>
            <th scope="col">위도</th>
            <th scope="col">경도</th>
            <th scope="col">날짜</th>
          </tr>
        </thead>
        <tbody>
          {% for report in report.all %}
          <tr>
            <td>{{ report.input_report }}</td>
            <td>{{ report.input_lat }}</td>
            <td>{{ report.input_lon }}</td>
            <td>{{ report.input_date }} {{ report.input_time }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </main>
    <footer class="mastfoot mt-auto">
      <div class="inner">
        <p class="text-muted font-weight-lighter">&copy; 2020. <a
            href="https://www.instagram.com/integer_ji/">IntegerJi</a> all rights reserved.</p>
      </div>
    </footer>
  </div>
</body>
{% endblock %}
  • 29 ~ 36 : for문을 사용하여 report의 모든 객체를 각각의 이름으로 반환해 준다.

 

views.py/list

def list(request):
    report = Report.objects.filter(input_user=request.user).order_by('-input_date')
    return render(request, 'list.html', {'report':report })
  • report에 현재 접속자의 Report 객체를 input_date의 역순으로 넣어준다.