[英]AttributeError: 'QuerySet' object has no attribute 'requestedDate'
I just want to filter the CustomerPurchaseOrder(inputdate) to CustomerPurchaseOrderDetail(requestedDate).我只想将 CustomerPurchaseOrder(inputdate) 过滤为 CustomerPurchaseOrderDetail(requestedDate)。 How do i do that?我怎么做?
This is my current views.py这是我当前的 views.py
record = CustomerPurchaseOrder.objects.filter(profile__in=client.values_list('id'))
date = CustomerPurchaseOrder.objects.filter(profile__in=client.values_list('id'))
status = CustomerPurchaseOrderDetail.objects.filter(profile__in=client.values_list('id')) \
.filter(customer_Purchase_Order__in=record.values_list('id')).filter(inputdate=date.requestedDate)
this is my models这是我的模特
class CustomerPurchaseOrder(models.Model):
profile = models.ForeignKey(Customer,
on_delete=models.SET_NULL, null=True, blank=True,
verbose_name="Client Account")
customerdeliveryaddress = models.ForeignKey(CustomerDeliveryAddress,
on_delete=models.SET_NULL, null=True, blank=True,
verbose_name="Delivery Address")
process = models.ForeignKey('Process',
on_delete=models.SET_NULL, null=True, blank=True,
verbose_name="Process")
requestedDate = models.DateField(auto_now_add=True)
class CustomerPurchaseOrderDetail(models.Model):
profile = models.ForeignKey(Customer,
on_delete=models.SET_NULL, null=True, blank=True,
verbose_name="Client Account")
products = models.ForeignKey(Product,
on_delete=models.SET_NULL, null=True, blank=True,
verbose_name="Product")
customer_Purchase_Order = models.ForeignKey(CustomerPurchaseOrder,
on_delete=models.SET_NULL, null=True, blank=True,
verbose_name="CustomerPurchaseOrder")
inputdate = models.DateField(auto_now_add=True)
This is my full traceback这是我的完整回溯
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\decorators.py" in wrapper_func
42. return view_func(request, *args, **kwargs)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
21. return view_func(request, *args, **kwargs)
File "C:\Users\User\Desktop\LastProject\OnlinePalengke\customAdmin\views.py" in client
116. .filter(customer_Purchase_Order__in=record.values_list('id')).filter(inputdate=records.requestedDate)
Exception Type: AttributeError at /client/
Exception Value: 'QuerySet' object has no attribute 'requestedDate'异常值:“QuerySet”object 没有属性“requestedDate”
UPDATE更新
when i tried this当我尝试这个
status = CustomerPurchaseOrderDetail.objects.filter(profile__in=client.values_list('id')) \
.filter(customer_Purchase_Order__in=record.values_list('id')).filter(inputdate=date.values('requestedDate'))
I receive this error我收到这个错误
The QuerySet value for an exact lookup must be limited to one result using slicing.
You can try like this with F()
expression which allows you to access model fields from the very same object:您可以使用F()
表达式尝试这样,它允许您从同一个 object 访问 model 字段:
status = CustomerPurchaseOrderDetail.objects.filter(profile__in=client.values_list('id')) \
.filter(customer_Purchase_Order__in=record.values_list('id')).filter(inputdate=F('customer_Purchase_Order__requestedDate'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.