I was following the Django docs for Model Inheritance. There was a line: To inherit Meta options from multiple abstract base classes, you must explicitly declare the Meta inheritance
, But it is not working. It is extending the Meta attributes in the Model class’s meta attribute but when I am accessing Meta
on the child model class then it gives me the options from the first parent base class which is CommonInfo
in this case. It is happening because we are extracting the Model class’s own attributes like its own Meta in django.db.models.Model
metaclass ModelBase
.
from django.db import models
class CommonInfo(models.Model):
name = models.CharField(max_length=100)
age = models.PositiveIntegerField()
class Meta:
abstract = True
ordering = ["name"]
class Unmanaged(models.Model):
class Meta:
abstract = True
managed = False
class Student(CommonInfo, Unmanaged):
home_group = models.CharField(max_length=5)
class Meta(CommonInfo.Meta, Unmanaged.Meta):
pass
When I am accessing Student.Meta.managed
, it will give AttributeError: type object 'Meta' has no attribute 'managed'