Mysql django中抽象基类与泛型关系

Mysql django中抽象基类与泛型关系,mysql,django,database-design,django-models,abstract-class,Mysql,Django,Database Design,Django Models,Abstract Class,在django中使用泛型外键的抽象基类和泛型关系的优缺点是什么 抽象基类意味着一个带有子类的抽象类。以下是一个例子: class CommonInfo(models.Model): ... class Meta: abstract = True ordering = ['name'] class Student(CommonInfo): ... class Meta(CommonInfo.Meta): db_tab

在django中使用泛型外键的抽象基类和泛型关系的优缺点是什么

抽象基类意味着一个带有子类的抽象类。以下是一个例子:

class CommonInfo(models.Model):
    ...
    class Meta:
        abstract = True
        ordering = ['name']

class Student(CommonInfo):
    ...
    class Meta(CommonInfo.Meta):
        db_table = 'student_info'
class TaggedItem(models.Model):
    tag = models.SlugField()
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')
泛型关系是在单个表上使用具有对象id的泛型外键的实体。以下是一个例子:

class CommonInfo(models.Model):
    ...
    class Meta:
        abstract = True
        ordering = ['name']

class Student(CommonInfo):
    ...
    class Meta(CommonInfo.Meta):
        db_table = 'student_info'
class TaggedItem(models.Model):
    tag = models.SlugField()
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')

什么情况和/或什么时候应该使用一种或另一种解决方案的标准是什么?

经过一些研究,我认为抽象基类范式更符合自然关系数据库体系结构。泛型关系更像是黑客行为,绕过了引用完整性


抽象基类是一条出路。

@Daniel Roseman您对此有何看法?其中一种方法更好吗?