0

To speed up my admin page, I've decided to override my get_queryset() with a raw query however it results in:

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.

Is there some step I'm missing?. I've already confirmed that the query works in PSQL so I don't see what's going wrong. I've tried cutting it down to just the following but it still errors out.

def get_queryset(self, request):
    return MyObject.objects.raw('SELECT * FROM myapp_myobject')
Lorenzo Ang
  • 1,202
  • 3
  • 12
  • 35

1 Answers1

2

The problem is that raw return not a QuerySet instance but a RawQuerySet that do have iterator protocol and representation implemented but doesn't have a bunch of other methods used by Django views under the hood.

I advice to use extra instead or simply select ID column only from your raw query and then hit another one like MyObject.objects.filter(id__in=your_ids_list_from_raw)

Charnel
  • 4,222
  • 2
  • 16
  • 28