Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 3.x 如何将Django迭代器与值列表一起使用?_Python 3.x_Django_Django Queryset - Fatal编程技术网

Python 3.x 如何将Django迭代器与值列表一起使用?

Python 3.x 如何将Django迭代器与值列表一起使用?,python-3.x,django,django-queryset,Python 3.x,Django,Django Queryset,我有一个包含大量行的配置文件表。我试图根据super\u category和account\u id筛选出配置文件(这些是模型配置文件中的字段)。 假设我有一个ID列表,其形式为bulk\u account\u id和super\u categories list_of_ids = Profile.objects.filter(account_id__in=bulk_account_ids, super_category__in=super_categories).values_list('id

我有一个包含大量行的配置文件表。我试图根据
super\u category
account\u id
筛选出配置文件(这些是模型配置文件中的字段)。 假设我有一个ID列表,其形式为
bulk\u account\u id
super\u categories

list_of_ids = Profile.objects.filter(account_id__in=bulk_account_ids, super_category__in=super_categories).values_list('id', flat=True))

list_of_ids = list(list_of_ids)

SomeTask.delay(ids=list_of_ids)
此特定查询在第二行中求值时超时。 我可以在查询结束时使用
.iterator()
来优化它吗?
i、 e
list(list\u of_id.iterator())
,如果不是的话,我还能做什么?

只要你正在形成一个
list()
…不。更一般地说,只要你需要将所有实际对象传递到
某个任务中。延迟
,不。这只需要将所有对象从数据库读入内存,这需要时间。如果
SomeTask.delay
接受的不是实际对象的实际列表,那么您可以在那里做一些事情。@deceze像这样使用迭代器
queryset.values\u list('pk',flat=True)。迭代器()
如果我们想在循环中运行queryset,它有意义吗?