具有事务的详细视图,事务与销售具有一对多关系。我想显示交易详情vi中的所有销售

2024-09-30 14:21:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在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 %}

Tags: divobjecttablecol交易h1amounttr