gpt4 book ai didi

django - "Cannot filter a query once a slice has been taken"

转载 作者:行者123 更新时间:2023-12-03 12:51:57 26 4
gpt4 key购买 nike

我收到这个错误

Caught AssertionError while rendering: Cannot filter a query once a slice has been taken.



在这条线上
{% if form.non_field_errors %} 

当我尝试这样做时
copy_pickup_address = ModelChoiceField(required=False, queryset=Address.objects.filter(shipment_pickup__user=user).order_by('-shipment_pickup__created')[:5])

但是我需要对它进行切片,因为我只想要最后 5 个地址。它呈现良好,直到我选择一个地址并提交表格。为什么不喜欢这个?我怎样才能绕过它?

最佳答案

解释在 https://docs.djangoproject.com/en/1.8/ref/models/querysets/ :

even though slicing an unevaluated QuerySet returns another unevaluated QuerySet, modifying it further (e.g., adding more filters, or modifying ordering) is not allowed, since that does not translate well into SQL and it would not have a clear meaning either.

关于django - "Cannot filter a query once a slice has been taken",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3470111/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com