Django multiple inheritance E005

The Django docs states that in order to use multiple inheritance, one of them must have

use explicit AutoField in base models

or

use a common ancestor to hold the AutoField

In my case, I have a common ancestor, as in the following setup (taken from the docs):

class Piece(models.Model):
    piece_id = models.AutoField(primary_key=True)

class Article(Piece):
    pass

class Book(Piece):
    pass

class BookReview(Book, Article):
    pass

      

Unfortunately, this results in the following error:

$ python manage.py check
SystemCheckError: System check identified some issues:

ERRORS:
testapp.BookReview: (models.E005) The field 'piece_ptr' from parent model 'testapp.book' clashes with the field 'piece_ptr' from parent model 'testapp.article'.

System check identified 1 issue (0 silenced).

      

How to get around this?


EDIT: Django version is 1.8.2

+3


source to share


1 answer


I just found out that I can call a parent reference:

class Piece(models.Model):
    pass

class Article(Piece):
    article_to_piece = models.OneToOneField(Piece, parent_link=True)

class Book(Piece):
    book_to_piece = models.OneToOneField(Piece, parent_link=True)

class BookReview(Book, Article):
    pass

      



I'm still curious about other solutions!

+1


source







All Articles