Django:使用第三方应用程序作为django应用程序

时间:2014-08-18 14:44:28

标签: django django-south

之前我使用的是虚拟环境中的django-taggit应用。现在我需要添加一个 taggit app的Profile模型的自定义字段外键(Tag)。 我将taggit应用程序从虚拟环境移动到了应用程序目录,并交叉检查该应用程序的路径:

<module 'taggit' from '/home/user/VIR/poll/taggit/__init__.pyc'>

标记似乎在这一点上正常工作。

Tag模型中

进行了以下更改:

from profile.models import Profile

class Tag(TagBase):
    profile = models.ForeignKey(Profile)
    class Meta:
        verbose_name = _("Tag")
        verbose_name_plural = _("Tags")

在运行schemamigration时遇到错误:

ImportError: cannot import name Profile

任何洞察力问题?

1 个答案:

答案 0 :(得分:0)

也许您在Tag中使用profile.models,因此有循环导入,Python可以处理它。

如果要防止循环导入问题,可以删除from profile.models import Profile并使用外键的延迟模型定义:

class Tag(TagBase):
    profile = models.ForeignKey('profile.Profile')

我不了解您情况中的详细信息,但我认为您错误地使用 django-taggit 。默认情况下,标签使用通用外键,您不需要显式外键指向您的模型http://django-taggit.readthedocs.org/en/latest/getting_started.html