为了加快我的管理页面的速度,我决定用原始查询覆盖get_queryset()
,但结果如下:
Database error: Something’s wrong with your database installation. Make sure the appropriate database tables have been created, and make sure the database is readable by the appropriate user.
我缺少一些步骤吗?我已经确认查询可以在PSQL中运行,所以我看不到出了什么问题。我尝试将其缩减为以下内容,但仍然会出错。
def get_queryset(self, request):
return MyObject.objects.raw('SELECT * FROM myapp_myobject')
答案 0 :(得分:0)
问题是raw
返回的不是QuerySet实例,而是返回的RawQuerySet确实实现了迭代器协议和表示,但是没有Django视图使用的其他方法在引擎盖下。
我建议改用extra或直接从原始查询中选择ID列,然后再打另一个MyObject.objects.filter(id__in=your_ids_list_from_raw)