我真的不理解这个,如果有人能够解释一下这是怎么工作的,我会非常感激。我有两个应用程序,一个是“账户(Accounts)”,另一个是“主题(Theme)”......以下是我的设置列表:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'accounts',
'themes',
)
在账户中,我正在尝试做这件事:
from themes.models import Theme
class Account(models.Model):
ACTIVE_STATUS = 1
DEACTIVE_STATUS = 2
ARCHIVE_STATUS = 3
STATUS_CHOICES = (
(ACTIVE_STATUS, ('Active')),
(DEACTIVE_STATUS, ('Deactive')),
(ARCHIVE_STATUS, ('Archived')),
)
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=250)
slug = models.SlugField(unique=True, verbose_name='URL Slug')
status = models.IntegerField(choices=STATUS_CHOICES, default=ACTIVE_STATUS, max_length=1)
owner = models.ForeignKey(User)
enable_comments = models.BooleanField(default=True)
theme = models.ForeignKey(Theme)
date_created = models.DateTimeField(default=datetime.now)
在我的主题模型中:
class Theme(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=250)
slug = models.SlugField(unique=True, verbose_name='URL Slug')
date_created = models.DateTimeField(default=datetime.now)
class Stylesheet(models.Model):
id = models.AutoField(primary_key=True)
account = models.ForeignKey(Account)
date_created = models.DateTimeField(default=datetime.now)
content = models.TextField()
Django 抛出了以下错误:
from themes.models import Theme
ImportError: cannot import name Theme
这是某种循环导入问题吗?我尝试使用延迟引用,但似乎也不起作用!
Theme
的模块中导入Account
? - Dominic Rodger