Podchaser Logo
Home
Model Inheritance Django

Model Inheritance Django

Released Thursday, 28th May 2020
Good episode? Give it some love!
Model Inheritance Django

Model Inheritance Django

Model Inheritance Django

Model Inheritance Django

Thursday, 28th May 2020
Good episode? Give it some love!
Rate Episode

LinkedIn - https://www.linkedin.com/in/alex-cher/


Model inheritance in Django works almost identically to the way normal class inheritance works in Python, but the basics at the beginning of the page should still be followed. That means the base class should subclass django.db.models.Model.


The only decision you have to make is whether you want the parent models to be models in their own right (with their own database tables), or if the parents are just holders of common information that will only be visible through the child models.

There are three styles of inheritance that are possible in Django.

  1. Often, you will just want to use the parent class to hold information that you don’t want to have to type out for each child model. This class isn’t going to ever be used in isolation, so Abstract base classes are what you’re after.
  2. If you’re subclassing an existing model (perhaps something from another application entirely) and want each model to have its own database table, Multi-table inheritance is the way to go.
  3. Finally, if you only want to modify the Python-level behavior of a model, without changing the models fields in any way, you can use Proxy models.



Apple Podcasts - https://link.chtbl.com/Apple_Podcasts

Spotify - https://link.chtbl.com/8_-EyCh1

Google Podcasts - https://link.chtbl.com/kQr7HKma

Castbox - https://link.chtbl.com/rVlRcBZN


https://docs.djangoproject.com/en/3.0/topics/db/models/#model-inheritance



Get early access and exclusive content:

https://www.patreon.com/angrydeveloper

Show More
Rate

Join Podchaser to...

  • Rate podcasts and episodes
  • Follow podcasts and creators
  • Create podcast and episode lists
  • & much more

Episode Tags

Do you host or manage this podcast?
Claim and edit this page to your liking.
,

Unlock more with Podchaser Pro

  • Audience Insights
  • Contact Information
  • Demographics
  • Charts
  • Sponsor History
  • and More!
Pro Features