Skip to content Skip to sidebar Skip to footer

Multiple Inheritance From Abstract Classes With Same Parent But Different Child? Django

I have read few threads and know that for sure django can have multiple abstract classes. But pretty much all the samples I saw are... class AbsOne(models.Model): pass class A

Solution 1:

Just as with Python’s subclassing, it’s possible for a Django model to inherit from multiple parent models. Keep in mind that normal Python name resolution rules apply. The first base class that a particular name (e.g. Meta) appears in will be the one that is used; for example, this means that if multiple parents contain a Meta class, only the first one is going to be used, and all others will be ignored.

https://docs.djangoproject.com/en/1.11/topics/db/models/#multiple-inheritance

It's possible but it has some restrictions like ( overriding fields in parent class and meta classes ) and in Django ORM or the model way of classes is a bit different in architecture than regular python inheritance, read carefully what the documentation mentions and try to keep it simple.

... The main use-case where this is useful is for “mix-in” classes: adding a particular extra field or method to every class that inherits the mix-in. Try to keep your inheritance hierarchies as simple and straightforward as possible so that you won’t have to struggle to work out where a particular piece of information is coming from

edited: added another quote :)

Post a Comment for "Multiple Inheritance From Abstract Classes With Same Parent But Different Child? Django"