0

I having problem running my custom command, as it will throw a NameError: global name "graphofknowledge" is not defined. My file structure is

projectFile
|-manage.py
|-..
|-graphofknowledge (app)
  |-models.py
  |-views.py
  |-management
    |-__init__.py
    |-commands
      |-__init__.py
      |-customCommand.py

Here is the code for my custom command

from django.core.management.base import BaseCommand
from graphofknowledge.models import TagTrend_refine
class Command(BaseCommand):
    args = '<foo bar ...>'
    help = 'our help string comes here'
    def loadTagTrend(self, fileName):
        listOfData = []
        f = open(fileName)
        lines = f.readlines()
        f.close()
        for line in lines:
            temp = line.strip().split("\t")
            data = TagTrend_refine(
            tag = temp[0],
            trendData = temp[1]
            )
            listOfData.append(data)
        TagTrend_refine.objects.bulk_create(listOfEntities)

    def handle(self, *args, **options):
        self.loadTagTrend(graphofknowledge/tagTrend_refine.txt)

I added the app name into the INSTALLED APP. It works when I run a print out in the custom command. But once i add the import statement for my models, it will throw the NameError. May I know how can I solve this problem?

Kamlesh
  • 2,032
  • 2
  • 19
  • 35
LeonBrain
  • 347
  • 1
  • 3
  • 15

1 Answers1

2

It looks like you have forgotten use quotes for your filename string. Try:

    self.loadTagTrend('graphofknowledge/tagTrend_refine.txt')
Alasdair
  • 298,606
  • 55
  • 578
  • 516