def make_inactive_productlist_query(queryset):
now = timezone.now()
# Create a query of things are definitively inactive. Some of the ones
# filtered here might be out of stock, but we include that later.
inactive_candidates = (
queryset
.exclude(
Q(active=True)
& (Q(deactivate_date=None) | Q(deactivate_date__gte=now)))
.values("id")
)
inactive_out_of_stock = (
queryset
.filter(sale__timestamp__gt=F("start_date"))
.annotate(c=Count("sale__id"))
.filter(c__gte=F("quantity"))
.values("id")
)
return (
queryset
.filter(
Q(id__in=inactive_candidates)
| Q(id__in=inactive_out_of_stock))
)
评论列表
文章目录