我正在使用django 1.5.1并尝试移动管理命令。我有一个名为patient的应用程序,这是目录结构。
patient/
├── __init__.py
├── forms.py
├── management
│ ├── __init.py__
│ └── commands
│ ├── __init.py__
│ └── recall1.py
├── models.py
├── urls.py
├── views.py
当我尝试运行recall1命令时会发生以下情况:
$ python manage.py recall1
Unknown command: 'recall1'
以下是我的代码的样子:
from django.core.management.base import BaseCommand, CommandError
from recall.model import PatientRecalls, RecallType, RecallMessage
from patient.model import Patient
class Command(BaseCommand):
args = '<patient_id patient_id ...>'
def handle(self, *args, **options):
for patient_id in args:
try:
patient = Patient.objects.get(pk=int(patient_id))
except Patient.DoesNotExist:
raise CommandError('Patient "%s" does not exist' % patient_id)
patient.opened = False
patient.save()
self.stdout.write('Successfully closed patient "%s"' % patient_id)
在我运行这件事之前,我需要纠正什么错误?该应用程序运行良好,除了这个问题..
答案 0 :(得分:4)
您的文件名__init.py__
在__init__.py
和management/
commands/