我有 2 个应用程序:coworkers和services,每个都有自己的 models.py
在同事 models.py 中,我可以“从 services.models 导入服务”。
当我尝试在 services models.py 中“从 coworkers.models 导入状态”时,我收到以下错误消息:
Traceback(最近一次通话最后):文件“/Users/lucas/Documents/projetos/cwk-manager/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/management /commands/runserver.py”,第 91 行,inner_run self.validate(display_num_errors=True) 文件“/Users/lucas/Documents/projetos/cwk-manager/lib/python2.7/site-packages/Django-1.4. 3-py2.7.egg/django/core/management/base.py”,第 266 行,验证 num_errors = get_validation_errors(s, app) 文件“/Users/lucas/Documents/projetos/cwk-manager/lib/python2 .7/site-packages/Django-1.4.3-py2.7.egg/django/core/management/validation.py”,第 30 行,在 get_validation_errors for (app_name, error) in get_app_errors().items():文件“/Users/lucas/Documents/projetos/cwk-manager/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/db/models/loading.py”,第 158 行,在 get_app_errors self._populate() 文件“/Users/lucas/Documents/projetos/cwk-manager/lib/python2.7/site-packages/Django- 1.4.3-py2.7.egg/django/db/models/loading.py”,第 64 行,在 _populate self.load_app(app_name, True) 文件“/Users/lucas/Documents/projetos/cwk-manager/lib /python2.7/site-packages/Django-1.4.3-py2.7.egg/django/db/models/loading.py",第 88 行,在 load_app 模型 = import_module('.models', app_name) 文件中" /Users/lucas/Documents/projetos/cwk-manager/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/utils/importlib.py”,第 35 行,在 import_moduleegg/django/db/models/loading.py”,第 64 行,在 _populate self.load_app(app_name, True) 文件“/Users/lucas/Documents/projetos/cwk-manager/lib/python2.7/site-packages /Django-1.4.3-py2.7.egg/django/db/models/loading.py”,第 88 行,在 load_app 模型 = import_module('.models', app_name) 文件“/Users/lucas/Documents/projetos /cwk-manager/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/utils/importlib.py”,第 35 行,在 import_moduleegg/django/db/models/loading.py”,第 64 行,在 _populate self.load_app(app_name, True) 文件“/Users/lucas/Documents/projetos/cwk-manager/lib/python2.7/site-packages /Django-1.4.3-py2.7.egg/django/db/models/loading.py”,第 88 行,在 load_app 模型 = import_module('.models', app_name) 文件“/Users/lucas/Documents/projetos /cwk-manager/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/utils/importlib.py”,第 35 行,在 import_module/Users/lucas/Documents/projetos/cwk-manager/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/utils/importlib.py”,第 35 行,在 import_module/Users/lucas/Documents/projetos/cwk-manager/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/utils/importlib.py”,第 35 行,在 import_module 导入(名称)文件“/Users/lucas/Documents/projetos/cwk-manager/cwk-manager/cwk_manager/coworkers/models.py”,第 2 行,从 services.models 导入服务文件“/Users/lucas/Documents /projetos/cwk-manager/cwk-manager/cwk_manager/services/models.py”,第 5 行,在类 Services(models.Model):文件“/Users/lucas/Documents/projetos/cwk-manager/cwk-manager /cwk_manager/services/models.py",第 11 行,在 Services status = models.ForeignKey(Status) NameError: name 'Status' is not defined
--
同事模型.py
from django.db import models
from services.models import Services
class Status(models.Model):
status_name = models.CharField(max_length=50)
status_description = models.TextField(blank=True, null=True)
class Meta:
verbose_name = "Status"
verbose_name_plural = "Status"
def __unicode__(self):
return self.status_name
服务模型.py
from django.db import models
from coworkers.models import Status
# This table contains all the information about plans and other general services provided.
class Services(models.Model):
service_name = models.CharField(max_length=100)
service_description = models.TextField(blank=True, null=True)
service_price = models.DecimalField(max_digits=7, decimal_places=2, blank=True, null=True)
creation_date = models.DateField(auto_now_add=True)
last_update = models.DateField(auto_now=True)
status = models.ForeignKey(Status)
class Meta:
verbose_name = "Services"
verbose_name_plural = "Services"
def __unicode__(self):
return self.service_name
- 有人可以帮我看看我做错了什么吗?
提前致谢!