2013-05-15 43 views
1

大家好人都可以帮助我这个我有导入错误,当我做一个导入我认为它的所有冲突。所有罚款,直到我导入B,因为我真的需要一个ForeignKey从A.交叉导入时导入错误django/python

一个/ 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

b
from a.models import A 
Class C(): 
    a = models.ForeignKey(A) 

回答

5

你可以做到这一点(不导入B型,只要输入格式 “app_name.model_name” 的字符串)

A/models.py

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

ForeignKey docs

+0

这个工程很好,谢谢一百万 – user1940979