[Answered ]-Django object.raw('query') doesnot return updated queryset

1👍

I think the reason of this behavior is that raw execute query during class construction. Here’s what documentation saying:

takes a raw SQL query, executes it, and returns a django.db.models.query.RawQuerySet instance

In other words – your query run one’s when you start the project, not each time you call the view.
Instead of queryset class attribute you can define a get_queryset method and put your raw query there, so that it will be called (and query will be executed) each time you call the view with request:

def get_queryset(self):
    return model_name.objects.raw('call stored_procedure();')

Leave a comment