I am trying to make a custom command to run on my celery crontabs, which extracts data from my db, makes a list, and then dumps that information as a list in redis. This list will then be used by other workers.
However, I am getting a NameError, which I haven’t been able to solve despite reading relevant stack and Google posts.
My code below:
from django.core.management.base import NoArgsCommand, CommandError
from detail.models import SD
import redis
class Command(NoArgsCommand):
help = 'Gathers the symbols from the database and generates a list for crontabs, saving to redis.'
def handle_noargs(self, **options):
all = SD.objects.all()
data = []
for info in all:
data.append(info.symb)
r = redis.Redis()
try:
r.delete('allsymbols')
except:
pass
for xyz in data: **<---- the NameError refers to this line**
r.rpush('allsymbols', xyz)
TRACEBACK
File "C:\.....command.py", line 5, in <module>
class Command(NoArgsCommand):
File "C:\.....command.py", line 26, in Command
for xyz in data:
NameError: name ‘data’ is not defined
Script contains mixed tabs and spaces.
You should rather use only spaces, as per pep8, but the choice is yours, as long as you use the same in all your scripts.