There's more...

In normal Python class inheritance, if there is more than one base class, and all of them implement a specific method, and you call that method on the instance of a child class, only the method from the first parent class will be called, as in the following example:

>>> class A(object):
... def test(self):
... print("A.test() called")
...

>>> class B(object):
... def test(self):
... print("B.test() called")
...

>>> class C(object):
... def test(self):
... print("C.test() called")
...

>>> class D(A, B, C):
... def test(self):
... super().test()
... print("D.test() called")

>>> d = D()
>>> d.test()
A.test() called
D.test() called

This is the same for Django model base classes; however, there is one special exception.

The Django framework does some magic with metaclasses that calls the save() and delete() methods from each of the base classes.

That means that you can confidently do pre-save, post-save, pre-delete, and post-delete manipulations for specific fields defined specifically in the mixin by overwriting the save() and delete() methods.

To learn more about the different types of model inheritance, refer to the official Django documentation, available at https://docs.djangoproject.com/en/2.2/topics/db/models/#model-inheritance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.168.172