From 5d2f5dd4cc5234a97d69af8740ba862c2051fd43 Mon Sep 17 00:00:00 2001 From: Greg Kaleka Date: Fri, 3 Apr 2020 17:09:14 -0700 Subject: [PATCH] Doc'd Meta inheritance from abstract parents. --- docs/topics/db/models.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt index 9fab17872e..dd9fc3aa54 100644 --- a/docs/topics/db/models.txt +++ b/docs/topics/db/models.txt @@ -964,6 +964,33 @@ abstract base class. For example, including ``db_table`` would mean that all the child classes (the ones that don't specify their own :ref:`Meta `) would use the same database table, which is almost certainly not what you want. +Due to the way Python inheritance works, if a child class inherits from +multiple abstract base classes, only the :ref:`Meta ` options +from the first listed class will be inherited by default. To inherit :ref:`Meta +` options from multiple abstract base classes, you must +explicitly declare the :ref:`Meta ` inheritance. For example:: + + 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 + .. _abstract-related-name: Be careful with ``related_name`` and ``related_query_name``