Wednesday, May 16, 2012

Django NoArgsCommand gives NameError: name ' ' is not defined

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)




No comments:

Post a Comment