我想获得许多订单号,例如:
order_nrs = range(123460000, 123461500)
orders = Order.objects.filter(order_number__in=order_nrs)
实际上,订单nrs是未排序的,范围介于10000000和70000000之间
但是这会返回以下错误: DatabaseError:SQL变量太多
我找不到解决此问题的正确方法,我已尝试过bulk_in,但order_number不是主键。
答案 0 :(得分:1)
也许有更好的方法,但这个应该有效:
order_nrs = range(123460000, 123461500)
list = Order.objects.filter(order_number__lt=max(order_nrs), order_number__gt=min(order_nrs))
或者
list = Order.objects.filter(order_number__range=order_nrs)