2017-03-17 72 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

相關問題