Python 排除Django查询中注释项的计数
我正在查询数据库以获得对象列表,并使用annotate()计算它们与之关联的项的数量 我只想返回关联Python 排除Django查询中注释项的计数,python,django,Python,Django,我正在查询数据库以获得对象列表,并使用annotate()计算它们与之关联的项的数量 我只想返回关联项数大于5的对象 lists = List.objects.exclude(picture_url='').exclude(picture_url__icontains='google').select_related('city','city__country', 'user', 'user__profile').annotate(items_added=Count('item'))[:10]
项数大于5的对象
lists = List.objects.exclude(picture_url='').exclude(picture_url__icontains='google').select_related('city','city__country', 'user', 'user__profile').annotate(items_added=Count('item'))[:10]
与aggregate()不同,annotate()不是terminal子句。产量
annotate()子句是一个查询集;可以修改此查询集
使用任何其他QuerySet操作,包括filter()、order_by或
甚至对annotate()的其他调用
与aggregate()不同,annotate()不是terminal子句。产量
annotate()子句是一个查询集;可以修改此查询集
使用任何其他QuerySet操作,包括filter()、order_by或
甚至对annotate()的其他调用
实际上我的连接已暂停:)实际上我的连接已暂停:)
lists = List.objects.exclude(picture_url='') \
.exclude(picture_url__icontains='google') \
.select_related('city','city__country', 'user', 'user__profile') \
.annotate(items_added=Count('item')) \
.filter(items_added__gt=5)[:10]