Python : 解决这个循环导入难题

Python : Solving this cyclic import conundrum

我 运行 陷入进口难题。添加新导入后出现以下错误

from studentApp.models import modelStudent
  File abc, line 6, in <module>
    from interviewApp.models import modelInterviewQuestion
  File "xyz", line 4, in <module>
    from mainApp.models import modelPatient
ImportError: cannot import name modelPatient

现在这是我的文件的样子 mainApp/models.py

from studentApp.models import modelStudent #<---Added this and I get the error

这是我的 studentApp/models.py 文件

from interviewApp.models import modelInterviewQuestion #---> has a call to modelPatient inside
from mainApp.models import modelPatient 
from labApp.models import modelLabTestName #---> has a call to modelPatient inside

现在在我的 interviewApp/models.py 中我有这个导致循环导入

from mainApp.models import modelPatient #<---This is what is initiated the call

我明白为什么会这样,但我不确定如何解决这个问题。 有什么建议吗?

循环依赖是studentApp/models.py导入mainApp.modelsmainApp/models.py导入studentApp.models。一种解决方案是将 modelPatient 移动到它自己的模块中,然后将其导入 mainApp/models.pystudentApp/models.py.