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();')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…