【发布时间】:2012-09-19 16:34:41
【问题描述】:
我有两个模型,Product,它与 RatingEntry 是一对多的关系:
>>> product_entries = models.Products.objects.all()
>>> annotated = product_entries.annotate(Count("ratingentry"))
>>> len(annotated)
210
>>> a = annotated.filter(ratingentry__count__lte = 10)
>>> b = annotated.filter(ratingentry__count__gt = 10)
>>> len(a)
10
>>> len(b)
200
>>> len(a | b)
10 //should be 210
如果我将 a 和 b 更改为列表并将它们连接起来,则长度为 210。
知道这里发生了什么吗?
【问题讨论】:
标签: python django annotations