小编Kon*_*rov的帖子

如何排除具有空 prefetch_lated 字段的行

prefetch_related用过Prefetch

prefetch_qs = Offer.objects.filter(price__gt=1000)
prefetch = Prefetch('offers', queryset=prefetch_qs)
Run Code Online (Sandbox Code Playgroud)

如何排除包含空报价的行?它不起作用,因为注释计算了所有报价(未在 中过滤prefetch):

filtered_qs = Product.objects.annotate(
    offers_count=Count('offers')
).filter(
    offers_count__gt=0
).prefetch_related(
    prefetch      
)
Run Code Online (Sandbox Code Playgroud)

python django django-orm

2
推荐指数
1
解决办法
1386
查看次数

标签 统计

django ×1

django-orm ×1

python ×1