Python ValueError精确查找的QuerySet值必须限制为使用django视图切片的一个结果
我遇到了这个错误,我想不出解决的办法。这里是views.pyPython ValueError精确查找的QuerySet值必须限制为使用django视图切片的一个结果,python,html,django,django-views,Python,Html,Django,Django Views,我遇到了这个错误,我想不出解决的办法。这里是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.u
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 []
模板事务\列表\视图.html
{% extends "base.html" %}
{% block content %}
<h1>Transactions</h1>
<ul>
{% include "sellers/transaction_list.html" with transaction_list=object_list %}
</ul>
{% endblock %}
{%extends“base.html”%}
{%block content%}
交易
{%include“sellers/transaction_list.html”,其中transaction_list=object_list%}
{%endblock%}
以及事务处理_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>
产品
使用者
订单号
销售总额
{事务中的trans的%u列表%}
{{trans.product}}
{{trans.profile}}
{{trans.order_id}}
{{trans.amount}}
{{trans.timestamp | timesince}}年前
{%endfor%}
如果我将事务\u list\u view.html更改为包含部分
{%include“sellers/transaction_list.html”与
事务\u列表=事务%}
错误消失,但事务不显示 帐户s是一个
查询集
,这意味着它是一个包含零个、一个或多个SellerAccount的集合,因此您应该使用:
products = Product.objects.filter(seller__in=account)
在这里,您将返回交易
s,该交易有产品
,该交易有卖家
,该卖家有用户
自我请求。用户
您可以发布完整的回溯吗?它的简单帐户是queryset,包含多个结果,您正试图用它来过滤不正确的产品允许获取单个帐户或在中使用
def get_queryset(self):
return Transaction.objects.filter(product__seller__user=self.request.user)