为什么抽象=True dosen';django模型的元类中的t继承
我在django有这种型号:为什么抽象=True dosen';django模型的元类中的t继承,django,django-models,django-inheritance,Django,Django Models,Django Inheritance,我在django有这种型号: class FotherModel(models.Model): # Some fields goes here! class Meta: # Some fields goes here! abstract = True class ChildModel(FotherModel): # Some fields goes here! class Meta(FotherModel.Meta):
class FotherModel(models.Model):
# Some fields goes here!
class Meta:
# Some fields goes here!
abstract = True
class ChildModel(FotherModel):
# Some fields goes here!
class Meta(FotherModel.Meta):
#s Some fields goes here!
当我们从Django模型的meta类继承一个字段时,该字段出现在子meta类中,但该规则不适用于abstract=True
我知道如果发生这种情况,数据库中将不会创建任何表,但我不知道这种继承是如何发生的。请为我解释一下这个过程。由于meta部分中某些字段的概念和作用,在许多情况下,该字段由儿童继承是没有意义的
由于元节中某些字段的概念和作用,在许多情况下,该字段由儿童继承是没有意义的
已经描述了模型元类在模型的元类中重置
抽象
。在文档中,您可以看到:
Django确实对抽象基的元类进行了一次调整
类:在安装Meta属性之前,它将abstract设置为False。
这意味着抽象基类的子类不会自动
成为抽象类本身
此外,您可以在以下内容中看到此过程的源代码:
模型元类在模型的元类中重置
abstract
。在文档中,您可以看到:
Django确实对抽象基的元类进行了一次调整
类:在安装Meta属性之前,它将abstract设置为False。
这意味着抽象基类的子类不会自动
成为抽象类本身
此外,您可以在以下内容中看到此过程的源代码:
if abstract:
# Abstract base models can't be instantiated and don't appear in
# the list of models for an app. We do the final setup for them a
# little differently from normal models.
attr_meta.abstract = False
new_class.Meta = attr_meta
return new_class