Model Inheritance Styles in Django
1. Abstract Base Class Inheritance:
This style is used when you only want parents class to hold information that you don’t want to type out for each child model.
models.py
admin.py
When we migrate these changes than two tables created in database.
in Customer Table we have name,email,address and Phone fields.
in Staff Table we have name,email,address and position fields.
Base class Table is not created in This inheritance.
2.Multi Table Model Inheritance:
This style is used if you are sub-classing an existing model and need each model to have its own database table.
models.py
admin.py
Base class table is also created in this inheritance.
it will create a one to one field model relationship for Restaurant table from Place table.
3. Proxy Model Inheritance:
This style is used, if you only want to modify the Python level behaviour of the model, without changing the model’s fields.
You Inherit from base class and you can add your own properties except fields.
base class should not be abstract class.
we can not use multiple inheritance in proxy models.
The main use of this is to overwrite the main functionalities of existing model.
it always query on original model with overridden methods.
Conclusion:
Abstract Base Class:No table for base class ,Only for derived class
Multi Table:Create table for both base and derived class .
Proxy Model: