2010-03-04 34 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是另一种选择它已经有一段时间了,它的发展已经下降,但它提供了一些人仍然青睐的方法。

相关问题