2017-03-17 69 views
1

第一种情况,这个django应用程序模型构造有显着的性能差异吗?

app_1 - post_model_1 

app_2 - post_model_2 (has Foreign Key Field to post_model_1) 

app_3 - post_model_3 (has Foreign Key Field to post_model_1) 

第二种情况下,

app_1 - post_model_1, 
     post_model_2 (has Foreign Key Field to post_model_1), 
     post_model_3 (has Foreign Key Field to post_model_1), 

,如果我做的QuerySet喜欢把所有相关的帖子(不管它是什么post_model_2,或post_model_3)使用ForeignKeyField到post_model_1,

第一种情况和第二种情况有区别吗?

如果是,哪个更快?

回答

3

两者没有区别。他们是一样的。第一种情况下创建的表格(模型)与第二种情况下创建的表格(模型)相同。

请注意,Django应用程序不会确定数据库模型(表格),但Model可以。因此,在这两种情况下,您都有模型的确切结构(三个表,其中包含ForeignKey relatioships)。所以,它的“更快”或“更好”。

在第一种情况下,你会怎么做:

from app_1 import post_model_1 
from app_2 import post_model_2 
from app_3 import post_model_3 

,而在第二个,你会怎么做:

from app_1 import post_model_1, post_model_2, post_model_3 

的查询集仍将保持不变。

+0

谢谢!它有帮助。 – touchingtwist

相关问题