Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6771387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:25:32+00:00 2026-05-26T15:25:32+00:00

In my django project I have the following: apps1/models.py: Post (model) apps2/models.py: Blogs (model)

  • 0

In my django project I have the following:

apps1/models.py: Post (model)
apps2/models.py: Blogs (model)
apps2/functions.py: get_blogs (method)

The apps1/models.py file imports the Blogs model from apps2/models.py.
The apps2/models.py file imports the get_blogs method from apps2/functions.py.
The apps2/functions.py file import the Post model from apps1/models.py.

I am getting the following error:

ImportError at /
cannot import name Post

Traceback
admin.autodiscover()
<in file apps1/models.py>
from apps2.models import Blogs
<in file apps2/models.py>
from apps2.functions import get_blogs
<in file apps2/functions.py>
from apps1.models import Post

I thought it might be that the admin.autodiscover is importing the Post model first and then through an import loop, it is trying to import it again. Although I tried changing it to:

from apps1.models import Post as OtherPost

but that didn’t help. Any idea why this is happening? Is it because there is a loop now?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:25:33+00:00Added an answer on May 26, 2026 at 3:25 pm

    If the only reason you import Blogs in apps1.models is that you have a relationship field in Post, how about using a lazy relationship instead? As far as I understand, those were designed specifically to deal with import loops like the one you’re experiencing.

    It is quite easy, instead of

    from apps2.models import Blogs
    ...
    class Post(models.Model):
        ...
        my_blog = models.ForeignKey(Blogs)
    

    you use something like this:

    class Post(models.Model):
        ...
        my_blog = models.ForeignKey("apps2.Blogs")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django model as following class Project(models.Model) name=models.CharField(max_length=200) class Application(models.Model) proj=models.ForeignKey(Project, null=True,
Say I have two models in my Django project. class Project(models.Model): name = models.CharField(max_length=256)
OK, I have the following directory structure (it's a django project): -> project -->
I have worked a bit with Django and I quite like its project/applications model
I have the following models defined: class Team(models.Model): Name = models.CharField(max_length=250) class Fixture(models.Model): HomeTeam
In my django project, I have 4 models that are all tied together in
In my django project I have following LOGGING config: LOGGING = { 'version': 1,
I have a django project that I have been working on as a solo
So I have a django project I just created called 'coolprojectsite' the directory structure
I have a django project, but for some reason basic jquery isn't working. <html>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.