大家好我输入模型时遇到问题,我认为这与循环导入有关。我一直收到错误
cannot import name PurchaseOrder
尽管有这个模型
我的模特
class Project(MAIDEAModel):
office = models.ForeignKey(
Office,
related_name='projects',
help_text=_('Office which the project is under')
)
name = models.CharField(
_("Name"),
max_length=50,
validators=[MinLengthValidator(5), validate_sluggable],
help_text=_('Name of the project')
)
status = models.IntegerField(
_("Status"),
choices=STATUS,
default=STATUS_ACTIVE,
help_text=_('Activity status of the Project')
)
type = models.IntegerField(
_("Type"),
choices=PROJECT_TYPES,
help_text=_('Type of project')
class PurchaseOrder(MAIDEAModel):
""" This model holds PO numbers for a project
"""
project = models.ForeignKey(
Project,
related_name='purchase_orders',
)
number = models.BigIntegerField(
_('PO Number'),
validators=[MaxValueValidator(9999999999)]
)
所以当我导入
时来自maidea.apps.somalia.models导入Project,PurchaseOrder
我收到错误
ImportError Traceback (most recent call last)
<ipython-input-8-6ed2e10f0c28> in <module>()
----> 1 from maidea.apps.somalia.models import PurchaseOrder
ImportError: cannot import name PurchaseOrder
我尝试过使用
from django.apps.import apps
apps.get_model('somalia','PurchaseOrder')
我收到此错误
LookupError: App 'somalia' doesn't have a 'purchaseorder' model.
我正在运行django版
In [28]: django.VERSION
Out[28]: (1, 9, 5, 'final', 0)
我非常需要帮助,我在这里失踪了。 感谢