12π
Instead of importing the all project then the app then the module inside the app just import the app which is inside the project then the module.
Instead of
from webproject.app import model
Use
from app import model
or
from app.models import Staffs
5π
I think this bug report (turns out itβs a feature) is related to your problem.
For me the problem was resolved by importing from resume.models
only, rather than apps.resume.models
. So search for "from apps."
in your project and replace it.
(For me, removing __init__.py
or changing the PYTHONPATH
caused other problems, I imagine thatβs common.)
- [Django]-How to PATCH a single field using Django Rest Framework?
- [Django]-Default value for user ForeignKey with Django admin
- [Django]-Accessing dictionary by key in Django template
0π
This issue has a century, but here goes my solution that was really painful to find.
Given this project tree:
repo
βββ app
β βββ __init__.py
β βββ project
β β βββ __init__.py
β β βββ asgi.py
β β βββ settings.py
β β βββ urls.py
β β βββ utils.py
β β βββ wsgi.py
β βββ core
β β βββ __init__.py
β β βββ admin
β β β βββ __init__.py
β β β βββ ...
β β βββ apps.py
β β βββ models
β β β βββ __init__.py
β β β βββ mymodel.py
. . . ...
Besides having the core
folder included in the PYTHONPATH
, there were places where I was doing from ..models import MyModel
.
Apparently, using relative imports (..models
) was in some way generating the path from the repo folder app
, this is app.core.models
.
When running the tests, it assumed a duplication through sometimes refering the the same model in both paths: <app.core.models.MyModel>
and <core.models.MyModel>
, so I opted for using core.models
instead of ..models
.
- [Django]-Overriding AppConfig.ready()
- [Django]-Running "unique" tasks with celery
- [Django]-WARNING Not Found: /favicon.ico in Django