I would like to have a global variable in my django app that stores resulting list of objects that I later use in some functions and I don’t want to evaluate queryset more that once, i do it like this:
from app.models import StopWord
a = list(StopWord.objects.values_list('word', flat=True))
...
def some_func():
... (using a variable) ...
This seems ok to me but the problem is that syncdb and test command throw an exception:
django.db.utils.DatabaseError: (1146, "Table 'app_stopword' doesn't exist")
I don’t know how to get rid of this, may be I am on a wrong way?
Don’t initialize queries in a global scope. Bind
Noneto the name, then write a function that first checks if the value isNoneand if so generates the data, and then returns the value.