【发布时间】:2019-11-10 08:14:11
【问题描述】:
我遇到了这个错误,我想不出解决方法,这里是views.py
class SellerTransactionListView(ListView):
model = Transaction
template_name = "sellers/transaction_list_view.html"
def get_queryset(self):
account = SellerAccount.objects.filter(user=self.request.user)
if account.exists():
products = Product.objects.filter(seller=account)
return Transaction.objects.filter(product__in=products)
return []
模板 transaction_list_view.html
{% extends "base.html" %}
{% block content %}
<h1>Transactions</h1>
<ul>
{% include "sellers/transaction_list.html" with transaction_list=object_list %}
</ul>
{% endblock %}
还有transaction_list.html
<table>
<thead>
<th>Product</th>
<th>User</th>
<th>order_id</th>
<th>Sale Total</th>
<th></th>
</thead>
<tbody>
{% for trans in transaction_list %}
<tr>
<td>{{ trans.product }}</td>
<td>{{ trans.profile }}</td>
<td>{{ trans.order_id }}</td>
<td>{{ trans.amount }}</td>
<td>{{ trans.timestamp|timesince }} ago</td>
</tr>
{% endfor %}
</tbody>
</table>
如果我将 transaction_list_view.html 的包含部分更改为
{% 包括“sellers/transaction_list.html” transaction_list=交易 %}
错误消失但交易未显示。
【问题讨论】:
-
你能发布完整的回溯吗?
-
它的简单帐户是包含多个结果的查询集,您正在尝试使用它过滤产品,这不允许获得单个帐户或使用 IN
标签: python html django django-views