I have two django-apps. news and comments in news/models.py I import my comments with "from my_proj.comments.models import Comment" and in my comments/models.py I import my news class with "from my_proj.news.models import News"
Then in my third app (named frontpage) I import News in the view.py. But I get the error: Could not import hb_frontpage.views. Error was: cannot import name News
If I delete the import in the comments/models.py file (and the functions that uses News) it works. Anyone know how to solve this?
You don't actually need the News import at all. Looking at your code (which by the way should have been posted as an update to your question, not as an answer) the only reference to News is to look up the objects that are related to this particular comment. But Django has a built-in way of doing that from the comment itself:
news = self.news_set.all()
Using this, there's no need to get the News object and filter from there.
You can't do circular imports.
News needs comments to load, but to load comments you need to load news, but to load news you need to load comments but to load comments...
You should really only need to do one import. If you write what you are trying to do, I can give further advice.
精彩评论