Django select_related Examples |Django select_related and prefetch_related |Django n+1 Query Problem

preview_player
Показать описание
In this video, I'm gonna be showing you what exactly is select_related in Django. We will demonstrate Django select_related by making use of an example project which has two models and these models are related to each other using Foreign Key. We will show you what exactly is the use case of Django select_related by querying the Django models and showing the corresponding SQL queries being executed in the background by making use of django debug toolbar. We will then explain the problems with the default accessing method and specifically about the n+1 query problem in Django ORM. Then, we will fix the n+1 problem using Django select_related. We will also talk about the underlying SQL queries being executed if we use select_related. This video is a part of Django Relationships series and the next video in this Django Relationships series would be Django prefetch_related.

Subscribe | Code Band

Other videos in Code Band:

:) You Can Find Me On:
Рекомендации по теме
Комментарии
Автор

This makes so much more sense than the documentation. Thank you!

evanwhite
Автор

I was looking for this kind of explanation with example. What everyone does is just talks about theory. Thanks for making more sense by giving an example.

sayadahmedshaurov
Автор

Thank you ! The explanation is awesome)

ibpuzrl
Автор

Great explanation, bro. Thanks a lot!

behruzisaev
Автор

Your video is really great, up to the point and easy to understand, just onething.. Try being a bit faster.. I think the video could have been done in 5 minutes instead of 12.

ricardomoha
Автор

Great video and thanks for the tool, so useful! you saved hours of my life
Thanks again man

santiagobustamante
Автор

Hi which extension have you added on your browser to show requests and response time?

imranshaikh-btln
Автор

Thanks for select related
Please include prefetch related asap

harshamachine_learning
Автор

Brother, can you do a complete CRUD video with validation also? For the data input please use raw html forms. Without using Model Form or django form.

misfarsiddeek
Автор

Great explained. Thanks 😊 . If I want objects of Employee table from Department then what to do?
For an expample, I want some employees under a specific department. But I want it from the Department model not from Employee. That time what to do?

pritamghosh
Автор

So good ! Now how make a left join query with select_related please

bricegnanago
Автор

Sir... I want to output count employee per department. let's say I have 8 departments, and I want to outputing all department with and without employee. How can I do this? Thankyou

danarardiwinanto
Автор

we can use select_related only in ForeignKey case? or we can use with other joins also

deepanshuaggarwal
Автор

Getting error while migrations, Cannot add or update a child row, a foreign key constraint fails

pankaj
Автор

You should remove "prefetch_related" from the title. You don't talk about it

RedElectrik
Автор

Thank you. By the way, is it possible to use select_related in class-based view ?

yollaifliandry
Автор

What if an employee doesn't have a department?

jmdesros
Автор

Hi. Great brother.
May know that what is the different between mentioning Foreignkey, many to many and one to many in our model? Are they same?

misfarsiddeek