我有一个django应用程序,我想在基础级别定义两个类之间的关系。 定义这些基类的子项之间的关系对我来说也是有意义的 - 所以我得到这样的东西:
class BaseSummary(models.Model): base_types... class BaseDetail(models.Model): base_detail_types... base_summary = models.ForeignKey('BaseSummary') class ChildSummary(BaseSummary): child_summary_types... class ChildDetail(BaseDetail): child_detail_type... child_summary = models.ForeignKey('ChildSummary')django支持这个吗? 如果它受支持,这样的事情会导致可扩展性问题吗?
谢谢!
I've got a django app, where I'd like to define a relationship between two classes at a base level. It also makes sense to me to define the relationship between the children of those base classes - so that I get something like this:
class BaseSummary(models.Model): base_types... class BaseDetail(models.Model): base_detail_types... base_summary = models.ForeignKey('BaseSummary') class ChildSummary(BaseSummary): child_summary_types... class ChildDetail(BaseDetail): child_detail_type... child_summary = models.ForeignKey('ChildSummary')Does django support this? and If it is supported, is something like this going to cause scalability problems?
Thanks!
最满意答案
是的,这是支持的。 是的,它可能会导致性能问题。 你应该阅读Jacob关于模型继承的帖子: http : //jacobian.org/writing/concrete-inheritance/
从1.0开始,Django支持模型继承。 这是一个简洁的功能,可以大大提高您的建模选项的灵活性。
然而,模型继承也提供了一个非常好的机会射击自己的脚:具体(多表)继承。 如果您正在使用具体的继承,Django几乎在每个查询上都会创建隐式连接回父表。 这可能会彻底破坏数据库的性能。
Yes, this is supported. Yes, it can cause performance problems. You should read Jacob's post on model inheritance: http://jacobian.org/writing/concrete-inheritance/
Since 1.0, Django’s supported model inheritance. It’s a neat feature, and can go a long way towards increasing flexibility in your modeling options.
However, model inheritance also offers a really excellent opportunity to shoot yourself in the foot: concrete (multi-table) inheritance. If you’re using concrete inheritance, Django creates implicit joins back to the parent table on nearly every query. This can completely devastate your database’s performance.
更多推荐
发布评论