我正在做一个原始查询,其中我从表中选择 id 的结果如下所示:
[(517L,), (519L,), (526L,), (537L,), (668L,), (670L,), (671L,), (672L,), (673L,)]
我需要将这些 id 与 __in 过滤器一起使用来接收正确的对象,这是我的代码 注意我在这里编写的原始查询是一个虚拟查询,我的真实查询很复杂,这就是为什么我必须使用原始查询,
from django.db import connection, transaction
cursor = connection.cursor()
cursor.execute("SELECT id FROM table1 WHERE rule=1)
property_list= cursor.fetchall()
object_list = table1.objects.filter(pk__in=property_list)
这会导致以下错误:argument must be a string or a number, not 'list'
请指教