[1.11.x] Fixed #28332 -- Fixed diamond inheritence example in docs.
Backport of 473ab4610ef90be05f09127aa37cd20bcda5875e from master
This commit is contained in:
parent
07f73daf6b
commit
e921e98387
@ -1359,15 +1359,20 @@ use an explicit :class:`~django.db.models.AutoField` in the base models::
|
|||||||
class BookReview(Book, Article):
|
class BookReview(Book, Article):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
Or use a common ancestor to hold the :class:`~django.db.models.AutoField`::
|
Or use a common ancestor to hold the :class:`~django.db.models.AutoField`. This
|
||||||
|
requires using an explicit :class:`~django.db.models.OneToOneField` from each
|
||||||
|
parent model to the common ancestor to avoid a clash between the fields that
|
||||||
|
are automatically generated and inherited by the child::
|
||||||
|
|
||||||
class Piece(models.Model):
|
class Piece(models.Model):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Article(Piece):
|
class Article(Piece):
|
||||||
|
article_piece = models.OneToOneField(Piece, on_delete=models.CASCADE, parent_link=True)
|
||||||
...
|
...
|
||||||
|
|
||||||
class Book(Piece):
|
class Book(Piece):
|
||||||
|
book_piece = models.OneToOneField(Piece, on_delete=models.CASCADE, parent_link=True)
|
||||||
...
|
...
|
||||||
|
|
||||||
class BookReview(Book, Article):
|
class BookReview(Book, Article):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user