我有一些型号:
class OrdersTrigger(models.Model):
order = models.ForeignKey(Order, on_delete=models.CASCADE)
order_trigger = models.ForeignKey(Order, related_name='trigger', on_delete=models.CASCADE)
....
created_at = models.DateTimeField(auto_now_add=True)
class Order(models.Model):
from_bank = models.ForeignKey(Bank, on_delete=models.CASCADE)
to_bank = models.ForeignKey(Bank, related_name='to', on_delete=models.CASCADE)
我正在使用过滤器从该模型中获取订单清单:
orders = OrdersTrigger.objects.filter(Q(order__from_bank_=baseBank) & Q(order__to_bank=quoteBank))\
.filter(created_at__gte=latest_time).order_by('-created_at')
当我尝试遍历列表时:
for order in orders:
或
for order in orders.all():
我收到一个错误:
精确查询的QuerySet值必须限制为一个结果 使用切片。
您能帮我吗?我不明白如何解决此错误。