【问题标题】:What's the difference between OneToOne and Subclassing a model in DjangoOneToOne 和 Django 中的子类化模型有什么区别
【发布时间】:2023-03-10 09:22:02
【问题描述】:

例如:

class Subdomain(Site):
    #fields here

和

class Subdomain(models.Model):
    site = models.OneToOne(Site)
    #fields here

【问题讨论】:

    标签: python django django-models


    【解决方案1】:

    带有OneToOne 的模型有一个独立的PK;子模总是用超模的PK。

    【讨论】:

    • 两者在语义上有什么区别?您什么时候会使用其中一种?
    猜你喜欢
    • 2014-10-12
    • 2011-07-25
    • 2014-06-28
    • 2016-01-27
    • 1970-01-01
    • 2018-06-11
    • 2010-10-02
    • 1970-01-01
    • 2018-10-10
    相关资源
    最近更新 更多