Django Model Inheritance - InheritanceManager from django-model-utils

preview_player
Показать описание
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:

📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
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:

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:

#django #python
Рекомендации по теме
Комментарии
Автор

These Django Model tutorials are amazing!
Thank you so much BugBytes!
I hope you'll create more tutorials about designing Django database Models and querying them as this is 100% awesomeness. 🙏😀

silkogelman
Автор

Thank you! Is this the approach for creating subcategories for category parent model? Like for an ecommerce project, or do you maybe have a video on that?

TomislavMiletic
Автор

Man you're just amazing.
So many great videos!
On the topic, do you have an opinion about django-polymorphic?
It's another library I was looking at but haven't tried yet.

andreaszweili
Автор

Did I see in the very last part you got the last ok of subclassed MCQuestion of 4 but when you called get_subclass using 4 it returned a Boolean question?

Is this a bug in the InheritanceManager?

jamesmacbeth