The django-model-utils package provides us an InheritanceManager that we can apply to the base class when we have a model inheritance tree.
This allows us to retrieve the correct subclasses when querying, rather than simply getting instances of the parent class,
We will add django-model-utils and use this InheritanceManager in this video.
We'll see the two methods it adds to our Django Querysets:
1. select_subclasses()
2. get_subclass()
โถ๏ธ Full Playlist:
https://www.youtube.com/playlist?list=PL-2EBeDYMIbQIu4aMZYqM6_w1ihIKWIql
๐ ๐๐ต๐ฎ๐ฝ๐๐ฒ๐ฟ๐:
00:00 Intro
01:31 Querying parent model in shell
03:04 Installing django-model-utils
03:39 Adding InheritanceManager to parent model
06:59 Querying with get_subclass() function
โ๏ธ ๐๐๐ ๐บ๐ฒ ๐ฎ ๐ฐ๐ผ๐ณ๐ณ๐ฒ๐ฒ:
To support the channel and encourage new videos, please consider buying me a coffee here:
https://ko-fi.com/bugbytes
๐ฆ๐ผ๐ฐ๐ถ๐ฎ๐น ๐ ๐ฒ๐ฑ๐ถ๐ฎ:
๐ Blog: https://www.bugbytes.io/posts/
๐พ Github: https://github.com/bugbytes-io/
๐ฆ Twitter: https://twitter.com/bugbytesio
๐ถ TikTok: https://www.tiktok.com/@bugbytes.io
๐ ๐๐๐ฟ๐๐ต๐ฒ๐ฟ ๐ฟ๐ฒ๐ฎ๐ฑ๐ถ๐ป๐ด ๐ฎ๐ป๐ฑ ๐ถ๐ป๐ณ๐ผ๐ฟ๐บ๐ฎ๐๐ถ๐ผ๐ป:
Model Inheritance: https://docs.djangoproject.com/en/4.0/topics/db/models/#model-inheritance
django-model-utils:https://django-model-utils.readthedocs.io/en/latest/
#django #python