Python can';t将序列乘以类型为'的非整数;QuerySet';在Django 2.2.4中

Python can';t将序列乘以类型为'的非整数;QuerySet';在Django 2.2.4中,python,django,Python,Django,我在views.py中有这样一个逻辑,它将乘以相同型号中的数量和单价。我正在使用聚合,遇到了这个错误,无法将序列与'QuerySet'类型的非int相乘。 def updatecart(request): itemID = request.GET.get("itemID") cart = CustomerPurchaseOrderDetail.objects.filter(id = itemID) per_item_amount = CustomerP

我在views.py中有这样一个逻辑,它将乘以相同型号中的数量和单价。我正在使用聚合,遇到了这个错误,无法将序列与'QuerySet'类型的非int相乘。

def updatecart(request):
    itemID = request.GET.get("itemID")
    cart = CustomerPurchaseOrderDetail.objects.filter(id = itemID)
    per_item_amount = CustomerPurchaseOrderDetail.objects.filter(id = itemID).aggregate(total=Sum('unitprice' * cart.values_list('quantity')))
    print(per_item_amount)
    return render(request, 'customAdmin/add2cart.html', {"cart": cart})
这是我的模特

class CustomerPurchaseOrderDetail(models.Model):
    profile = models.ForeignKey(Customer,on_delete=models.SET_NULL, null=True, blank=True,verbose_name="Client Account")
    customer_Purchase_Order = models.ForeignKey(CustomerPurchaseOrder, on_delete=models.SET_NULL, null=True, blank=True, verbose_name="Customer Purchase Order")
    products = models.ForeignKey(Product,on_delete=models.SET_NULL, null=True, blank=True, verbose_name="Product")
    quantity = models.IntegerField(null=True, blank=True, default=1)
    unitprice = models.FloatField(max_length=500, null=True, blank=True)

    def __str__(self):
        suser = '{0.id}'
        return suser.format(self)
我该如何配置它

这是我的追踪

Traceback:

File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\exception.py" in inner
  34.             response = get_response(request)

File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  115.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\handlers\base.py" in _get_response
  113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "C:\Users\User\Desktop\LastProject\OnlinePalengke\customAdmin\views.py" in updatecart
  981.     per_item_amount = CustomerPurchaseOrderDetail.objects.filter(id = itemID).aggregate(total=Sum('unitprice' * cart.values_list('quantity')))

Exception Type: TypeError at /updatecart/
Exception Value: can't multiply sequence by non-int of type 'QuerySet'
你可以做:

from django.db.models import F, FloatField

CustomerPurchaseOrderDetail.objects.filter(
    id = itemID
).aggregate(
    total=Sum(
        F('unitprice') * F('quantity'),
        output_field=FloatField(),
    )
)['total']