Django自定义manage.py命令在app中调用函数

时间:2013-04-16 11:16:16

标签: django django-1.3

我有一个命令,用于从API下载数据,然后将其存储到本地数据库,它当前是我的应用程序的一部分,但我想添加从manage.py命令运行它的能力。 / p>

目前我只是试着调用它,因为我会在我的应用程序中使用正确的参数但是我得到与模型相关的错误

错误:

  File "C:\xxx\Development\working folder\appdata\globaltags\boughtintags.py", line 2, in <module>
    import appdata.boughtin.models as models
AttributeError: 'module' object has no attribute 'models'

我正在使用的当前代码:

class Command(BaseCommand):
    args = '<queryset_uuid queryset_item_uuid>'
    help = 'Downloads arbitrary items using a download script'

    def handle(self, *args, **options):
        for queryset_uuid, queryset_item_uuid in args:

            if download_queryset(queryset_uuid=queryset_uuid, queryset_item_uuid=queryset_item_uuid):
                self.stdout.write('Successfully downloaded "%s"\n' % queryset_item_uuid)
            else:
                raise CommandError('Unable to download "%s"\n' % queryset_item_uuid)

1 个答案:

答案 0 :(得分:0)

尝试将import appdata.boughtin.models as models中的boughtintags.py更改为

from appdata.boughtin import models