2
你好我正在分割我的文件,因爲模型越來越大。所以在這裏我們再次出現問題:循環導入python + django ?!如何使其工作?
我的模特; 如果在我的類別模型中,我刪除了「ArticleToCategory」和它的多對多關係。但我需要他們!
如何解決?
我刪除了model.py以便從模型包中加載文件。
類別(models.category):
class Category(MPTTModel):
# relationships
from RubeteDjango01.generic.models.article import Article
from RubeteDjango01.generic.models.article_to_category import ArticleToCategory
articles = m.ManyToManyField(Article, through=ArticleToCategory)
ArticleToCategory(models.article_to_category):
from django.db import models as m
class ArticleToCategory(m.Model):
from RubeteDjango01.generic.models.article import Article
from RubeteDjango01.generic.models.category import Category
article = m.ForeignKey(Article)
category = m.ForeignKey(Category)
class Meta:
db_table = 'articles_to_categories'
verbose_name_plural = 'ArticlesToCategories'
感謝
非常感謝!我試圖用點符號表示模塊的絕對路徑,但它不起作用。再次感謝;)你爲我節省了很多時間;)ps .:我喜歡你展示瞭如何從另一個應用程序導入模型。這真是太好了。 :D –
我得問你另外一件事:我可以在哪些地方使用這種表示法? post_save ...和類似的東西。? –
幾乎在其他地方你可以將import語句移入函數調用以避免循環導入問題 – second