我试图在django的详细视图中显示关系的许多方面。一笔交易可以有很多销售额
我的看法如下:
类TransactionDetailView(DetailView): 模型=事务
网址如下: 路径('transaction/',TransactionDetailView.as_view(),name='transaction-detail')
HTML格式如下:
<h1> Transaction</h1>
<br/>
<div class = "row">
<div class = "col-md-12">
<h4>Purchased Coins</h4>
<table class="table">
<thead>
<tr>
<th scope="col">Coin</th>
<th scope="col">Amount</th>
<th scope="col">per Coin</th>
<th scope="col">Total</th>
<th scope="col">Value Per Coin</th>
<th scope="col">Total Value</th>
<th scope="col">Date Added</th>
<th scope="col">Profit/Loss</th>
<th scope="col">%Profit/Loss</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{object.currency}}</td>
<td>{{object.amount}}</td>
<td>{{object.amount_per_coin}}</td>
<td>{{object.total_price}}</td>
<td><p>Get From API</p></td>
<td><p>{{object.amount}} * Get From API</p></td>
<td>{{object.date_purchased|date:"F d, Y"}}</td>
<td><p>TBC</p></td>
<td><p>TBC</p></td>
</tr>
</tbody>
</table>
{% for sale in object.sales %}
<p>kkk</p>
{% endfor %}
您需要的是使用SingleObjectMixin with a ListView,使用SingleObjectMixin提供
transaction
和ListView来列出所有相关的sales
相关问题 更多 >
编程相关推荐