diff options
| author | Greg Kaleka <greg@gregkaleka.com> | 2020-04-03 17:09:14 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-05-01 07:48:50 +0200 |
| commit | 5d2f5dd4cc5234a97d69af8740ba862c2051fd43 (patch) | |
| tree | 6d5a8c0e4928c11131b00b56171c31db73c399c3 | |
| parent | e972752504d9195583a0ec04515248c00138c1c0 (diff) | |
Doc'd Meta inheritance from abstract parents.
| -rw-r--r-- | docs/topics/db/models.txt | 27 |
1 files changed, 27 insertions, 0 deletions
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 <meta-options>`) 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 <meta-options>` options +from the first listed class will be inherited by default. To inherit :ref:`Meta +<meta-options>` options from multiple abstract base classes, you must +explicitly declare the :ref:`Meta <meta-options>` 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`` |
