2

大家好,任何人都可以帮我解决这个问题,我在导入时遇到了导入错误,我认为这一切都发生了冲突。在我导入 B 之前一切都很好,因为我真的需要从 A 到 B 的 ForeignKey。

一个/模型.py

from b.models import B #there is the problem
Class A():
    ....
    b = models.ForeignKey(B) # I really have to do this

b/模型.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)
4

1 回答 1

8

您可以这样做(不导入模型 B,只需键入格式为“app_name.model_name”的字符串)

一个/模型.py

Class A():
    ....
    b = models.ForeignKey("b.B")

外键文档

于 2013-05-15T20:31:16.387 回答