2

こんにちは、誰でも私を助けてくれますか? インポートを行うときにインポート エラーが発生しました。A から B への 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)
4

1 に答える 1

8

これを行うことができます (モデル B をインポートするのではなく、「app_name.model_name」の形式で文字列を入力するだけです)。

a/models.py

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

ForeignKey ドキュメント

于 2013-05-15T20:31:16.387 に答える