2010-03-04 38 views
0

假設我的SAAS中的帳戶類型爲Account(models.Model)。以下是一個好主意嗎?Django multi tennant體系結構 - 是否所有模型都有對tenn_id的引用

class MyModel(models.Model): 
    account = models.ForeignKey(Account) 
    spam = models.CharField(max_length=255) 

class MyOtherModel(models.Model): 
    # The next attribute `account` is the line in question. 
    # Should it be included even though mymodel.account can get the same value? 
    # The architecture could change later, and I might regret not including it, 
    # but I can't think of many reasons why, other than filtering a list out of 
    # this model like MyOtherModel.objects.filter(account=some_account).all() 
    # Are there other considerations? 
    account = models.ForeignKey(Account) 
    mymodel = models.ForeignKey(MyModel) 
    eggs = models.CharField(max_length=255) 

回答

1

如果你現在沒有使用它,我會放棄它。編寫你現在需要的東西,稍後再進行重構。有幾個工具可以使模式更改變得更加輕鬆。 South就是一個很好的例子 - 在許多情況下運行良好,並且持續成熟,並且擁有很好的社區支持。 django-evolution是另一種選擇它已經有一段時間了,它的發展已經下降,但它提供了一些人仍然青睞的方法。

相關問題