Skip to content

Commit

Permalink
feat : Create detail page to see trades
Browse files Browse the repository at this point in the history
Use sample data created by admin page.
main page has a list of region(동)
and detail pages have a list of real-estates of the region
and detail-trade pages have a list of trades of the real estate
Name of classes in View and Templates can be modified.
#8
  • Loading branch information
srlee056 committed Nov 7, 2023
1 parent 82b1572 commit c95d7c0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
13 changes: 13 additions & 0 deletions trades/templates/trades/detail-trade.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{estate.estate_name}}의 거래 내역 {% if trades %}
<ul>
{% for trade in trades %}
<li>
{{trade.trade_year}}년 {{trade.trade_month}}월 {{trade.trade_day}}일
<br />
거래가 : {{trade.trade_price}}
</li>
{% endfor %}
</ul>
{% else %}
<p>거래가 존재하지 않습니다.</p>
{% endif %}
14 changes: 11 additions & 3 deletions trades/templates/trades/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ <h1>{{region.dong_name}}의 집값 추이는?</h1>
<p>{{biggest_increase}}은 00%로 가장 많이 오른 지역입니다.</p>
<p>{{biggest_decrease}}은 00%로 가장 많이 떨어진 지역입니다.</p>

{% if estates %} {% for estate in estates %}
<p>{{estate.estate_name}}</p>
{% endfor %} {% else %}
{% if estates %}
<ul>
{% for estate in estates %}
<li>
<a href="{% url 'trades:detail-trade' region.id estate.id %}"
>{{estate.estate_name}}</a
>
</li>
{% endfor %}
</ul>
{% else %}
<p>no estates.</p>
{% endif %}
</li>
Expand Down
7 changes: 6 additions & 1 deletion trades/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@

urlpatterns = [
path("", views.index, name="index"),
path("<int:region_id>/detail/", views.detail, name="detail"),
path("detail/<int:region_id>/", views.detail, name="detail"),
path(
"detail/<int:region_id>/<int:estate_id>/",
views.detail_trade,
name="detail-trade",
),
]
13 changes: 13 additions & 0 deletions trades/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ def detail(request, region_id):
"estates": estates,
}
return render(request, "trades/detail.html", context)


def detail_trade(request, region_id, estate_id):
region = get_object_or_404(Region, pk=region_id)
estate = get_object_or_404(RealEstate, pk=estate_id)

real_estate_trades = estate.realestatetrade_set.all()
context = {
"region": region,
"estate": estate,
"trades": real_estate_trades,
}
return render(request, "trades/detail-trade.html", context)

0 comments on commit c95d7c0

Please sign in to comment.