[Answered ]-Django Model Import Error When trying to Import in Another App's Model

2👍

This is from Django Docs.

You must define or import all models in your application’s models.py or models/__init__.py. Otherwise, the application registry may not be fully populated at this point, which could cause the ORM to malfunction.

Once this stage completes, APIs that operate on models such as get_model() become usable.

https://docs.djangoproject.com/en/3.2/ref/applications/#how-applications-are-loaded

👤Ram

-1👍

Finally I got the solution from my own. Many peoples get into this problem I saw around me.

Here how I solved the problem:

project-name/
...project-name/
...apps1/
.....models.py
...apps2/
.....models.py
...manage.py

Just the basic django project structure.

Now to import the models of apps1 into apps2:
In apps2/models.py:

from apps1 import models as apps1Model

# Now accessing the models

apps1Model.Model1
apps1Model.Model2

Leave a comment