大家好,任何人都可以帮我解决这个问题我在进行导入时遇到导入错误我认为它的所有冲突都很好直到我导入B因为我真的需要从A创建一个ForeignKey到B.
A / models.py
from b.models import B #there is the problem
Class A():
....
b = models.ForeignKey(B) # I really have to do this
B / models.py
from c.models import C
Class B():
....
c = models.ForeignKey(C)
C / models.py
from a.models import A
Class C():
a = models.ForeignKey(A)
答案 0 :(得分:6)
您可以执行此操作(不导入模型B,只需键入格式为“app_name.model_name”的字符串)
A / models.py
Class A():
....
b = models.ForeignKey("b.B")