2013-07-17 28 views
0

所以,我有2個應用應用爲外鍵

├───Blog 
    post 
    comment 

└───User 
    profile 
  • 用戶(基本認證方式和外形儀表盤)

  • 博客(有基本的博客車型Django項目:交,評論)

我需要給用戶的可能性在同一個項目中創建一個或多個博客,但我不明白我可以如何像處理模型一樣處理應用程序。

唯一的解決方案,我想通過添加一個外鍵到用戶id爲每個模型與博客應用程序。但是有沒有更好的方法?

+4

不能你只需要添加一個博客的模型,並添加一個外鍵,用戶使用相關的名字嗎? – lalo

+0

但博客是一個有很多模型,而不是一個模型的應用程序。 –

回答

1

我認爲你應該做的是:

# blog/models.py 

class Blog(Model): 
    owner = ForeignKey(User, related_name="blogs") 
    name = Charfield() 

class Post(Model): 
    blog = ForeignKey(Blog, related_name="posts") 
    #Other fields ... 

class Comment(Model): 
    post = ForeignKey(Post, related_name="comments") 
    #Other fields ... 
+0

誠然,不是基於saas的應用程序需要安全和數據庫分離 –