Django prefetch_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 prefetch_related in Django. We will demonstrate Django prefetch_related by making use of an example project which has two models and these models are related to each other using a ManytoMany relationship. We will show you what exactly is the use case of Django prefetch_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 prefetch_related. We will also talk about the underlying SQL queries being executed if we use prefetch_related. At the end, we will also talk about the difference between prefetch_related and select_related, when to use Django select_related and when to use Django prefetch_related and so on. This video is a part of Django Relationships series.

Subscribe | Code Band

Other videos in Code Band:

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

Thank you! It is fantastic video. i liked way that demonstrated the use case.After watched videos i was thinking that why didn't see your videos before.

raufp
Автор

Amazing! Thank you for taking the time to explain this!

OrangesDaWin
Автор

thanks for making video as asked earlier
note you are the only one who made a tutorial video on this

harshamachine_learning
Автор

Nice . I was avoiding to learn these concepts from djangocon as there videos are very large. But you have helped me to learn what I needed.

shampysingh
Автор

Awesome way to demonstrate the concept 👍🏻

jaydevpatil
Автор

that's great vid and easy to understand

borin
Автор

You are doing great videos brother. Keep going.

misfarsiddeek
Автор

Very helpful & Informative. One small suggestion, please avoid putting background music in your videos :)

saimaruthi_
Автор

Great video, but the background music is very distracting when watching this.

asiannvasion
Автор

that background music did't bothered much to me but if you control that volume little low it would be great i feel

raghavendrasinghchouhan
Автор

in prefetch_related, we are getting list of stores that contain any book as output, not book wise store list. Am i right ?

deepanshuaggarwal
Автор

if possible make a video for pure graphql, graphene, graphene-django

vijayl
Автор

what if we use .last() instead of .all() while looping?

shriyahireholi
Автор

anybody can help me which django function we can use for left join or right join.

narendrathapa
Автор

you didnt say anythink new but de docs?

jorgeramiroalarconvargas
Автор

Please increase the font size it is not visible.

mohdkhalid
Автор

Please increase font size for this video bro. Not able to see the code ☹️

rangabharath
Автор

why did you use "store_set" instead of "books" like in documentation? books actually doesnt work, i dont know why
but "store_set" works

oruchkin
Автор

When making an explanation video please remove background music it is very distracting

affanarif
Автор

If we have three models

class Author(models.Model):
name =
class Book(models.Model):
name=
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='books')
class Blog(models.Model):
name=
author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='blogs)

if we are creating a detailed view of an Author (John), can we use the below querie to fetch all the Books and Blogs he has written?
author = Author.objects.prefetch_related('books_set',
for book in books_set.all():
print(book.name)
for blog in blogs_set.all():
print(blog.name)

saimaruthi_