Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 排除Django查询中注释项的计数_Python_Django - Fatal编程技术网

Python 排除Django查询中注释项的计数

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]

我正在查询数据库以获得对象列表,并使用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]
与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]