【问题标题】:Django custom manage.py commands calling functions in appDjango 自定义 manage.py 命令在应用程序中调用函数
【发布时间】:2013-04-08 18:35:46
【问题描述】:

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

目前我只是想在我的应用程序中使用正确的参数调用它,但我得到一个与模型相关的错误

错误:

  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)

【问题讨论】:

    标签: django django-1.3


    【解决方案1】:

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

    from appdata.boughtin import models
    

    【讨论】:

      猜你喜欢
      • 2014-05-21
      • 1970-01-01
      • 2010-10-28
      • 2013-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-13
      • 2017-12-02
      相关资源
      最近更新 更多