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

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ม.ค. 2025

ความคิดเห็น • 78

  • @raufp6
    @raufp6 11 หลายเดือนก่อน

    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.

  • @harshamachine_learning7831
    @harshamachine_learning7831 4 ปีที่แล้ว +1

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

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Thanks for the support❤️

  • @Oranges4DaWin
    @Oranges4DaWin 3 ปีที่แล้ว +2

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

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      Glad it was helpful!😊

  • @shampysingh913
    @shampysingh913 4 ปีที่แล้ว +1

    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.

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Glad to hear that! Keep learning😊

  • @jaydevpatil921
    @jaydevpatil921 3 ปีที่แล้ว +1

    Awesome way to demonstrate the concept 👍🏻

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      Very glad to hear that...Thanks a lot😊

  • @misfarsiddeek3105
    @misfarsiddeek3105 4 ปีที่แล้ว +1

    You are doing great videos brother. Keep going.

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +2

      Thanks a lot and keep supporting 😊

  • @anumalik9555
    @anumalik9555 3 ปีที่แล้ว +1

    very informative, thank you so much

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      Glad to hear that😊

  • @borin2882
    @borin2882 4 ปีที่แล้ว +1

    that's great vid and easy to understand

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Glad to hear that😊

  • @rangabharath4253
    @rangabharath4253 4 ปีที่แล้ว +1

    Awesome as always bro.

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Thanks❤️

  • @sajidhaabdulla5486
    @sajidhaabdulla5486 2 ปีที่แล้ว

    It was so useful thankyou

    • @CodeBand
      @CodeBand  2 ปีที่แล้ว +1

      Glad to hear that😊

  • @kobas8361
    @kobas8361 4 ปีที่แล้ว +1

    Nice and clear video!

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Thanks a lot..glad it helped..keep supporting😊

  • @vinodreddy1722
    @vinodreddy1722 3 ปีที่แล้ว +1

    Perfect one

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      Glad to hear that...😊

  • @mfsdrawings8600
    @mfsdrawings8600 4 ปีที่แล้ว +1

    Very nice

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Thanks❤️

  • @deepanshuaggarwal7042
    @deepanshuaggarwal7042 3 ปีที่แล้ว +1

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

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      I didn't exactly remember the case, but definitely the video tells it all...😊

  • @saimaruthi_1
    @saimaruthi_1 4 ปีที่แล้ว +4

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

    • @saimaruthi_1
      @saimaruthi_1 4 ปีที่แล้ว +1

      At least while you are talking

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +2

      Thanks a lot...❤️

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +2

      Sorry for the trouble...Newer videos doesn't have bgm...Thanks for the suggestion😊

    • @saimaruthi_1
      @saimaruthi_1 4 ปีที่แล้ว +1

      @@CodeBand thank you :)

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      😊

  • @asian1nvasion
    @asian1nvasion ปีที่แล้ว

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

  • @zoromahm
    @zoromahm 4 ปีที่แล้ว +1

    So useful, I share :)

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Awesome, thank you!

  • @prateeksarangi9187
    @prateeksarangi9187 3 ปีที่แล้ว +1

    Thanks

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      Welcome

  • @raghuflute
    @raghuflute 2 ปีที่แล้ว +1

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

    • @CodeBand
      @CodeBand  2 ปีที่แล้ว +1

      Sorry for the late reply...
      Yup, sure... for the next videos, I'll take care of it. Thanks for the suggestion.

  • @narendrathapa9898
    @narendrathapa9898 4 ปีที่แล้ว +1

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

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      It's best to deal with what you are trying to achieve, Google and stackoverflow will definitely have answers😊

    • @narendrathapa9898
      @narendrathapa9898 4 ปีที่แล้ว +1

      @@CodeBand if you have just simply ping me out :)

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      😊

  • @shriyahireholi7472
    @shriyahireholi7472 3 ปีที่แล้ว +1

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

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      Did you mean in book.store_set.all() ?
      Anyways, last() returns the last object in the queryset and you can check how the query is generated using the same Debug Toolbar...

  • @jorgeav527-xyz
    @jorgeav527-xyz 3 ปีที่แล้ว +1

    you didnt say anythink new but de docs?

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      I tried explaining the concepts using the docs, not exactly reading the docs...

  • @vijayl2906
    @vijayl2906 4 ปีที่แล้ว +2

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

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +2

      Great idea! Thanks😊
      I'm also planning to do a REST series. What's your view on this?

    • @vijayl2906
      @vijayl2906 4 ปีที่แล้ว +1

      @@CodeBand There are so many source for REST. if you have plan for that, no problem for us. Because your teaching always unique and understandable. But for graphql i think there are some limited videos. In my point of view i'm not understandable. Because they using graphql with node and react. so if possible make a clear video for graphql, graphene, graphene_django. without react and node. this is a follower request.

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +2

      @@vijayl2906 Definitely, will do that in the future bro...I always love to make unique videos, so, I will definitely turn to this one once I complete the pending videos/playlists. Thanks a lot bro for the support❤️

  • @oruchkin
    @oruchkin 3 ปีที่แล้ว +1

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

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว

      stackoverflow.com/questions/47619860/laravel-5-4-on-heroku-forbidden-you-dont-have-permission-to-access-on-this-s

    • @sujoydhar248
      @sujoydhar248 2 ปีที่แล้ว

      as its a manytomany relation, one book can be in multiple stores. store_set.all() fetch all the stores that has the book in it .

  • @NOSTALGICFOODSAGP
    @NOSTALGICFOODSAGP 4 ปีที่แล้ว +1

    Awsorm

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Thank yew❤️

  • @mohdkhalid6420
    @mohdkhalid6420 4 ปีที่แล้ว +1

    Please increase the font size it is not visible.

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Definitely bro, I'm very sorry for that mistake...I will definitely take care of that in future videos.
      ❤️

  • @rangabharath4253
    @rangabharath4253 4 ปีที่แล้ว +1

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

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +2

      I'm very sorry brother...It was my mistake and will definitely try to fix in future videos 😊

  • @saimaruthi_1
    @saimaruthi_1 4 ปีที่แล้ว +1

    If we have three models
    class Author(models.Model):
    name = models.CharField(max_length=50)
    class Book(models.Model):
    name= models.CharField(max_length=50)
    author = models.ForeignKey(Author,on_delete=models.CASCADE, related_name='books')
    class Blog(models.Model):
    name= models.CharField(max_length=50)
    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', 'blogs_set').get(name='John')
    for book in books_set.all():
    print(book.name)
    for blog in blogs_set.all():
    print(blog.name)

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      First thing, if you specify a related_name, then use that..(books, blogs instead of books_set, blogs_set)
      And I'm not sure whether that query works perfectly, please do a quick run and let me know...
      Although, you can chain prefetch_related results...
      stackoverflow.com/questions/27116770/prefetch-related-for-multiple-levels

    • @saimaruthi_1
      @saimaruthi_1 4 ปีที่แล้ว +1

      @@CodeBand Thank you

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว

      @@saimaruthi_1 Keep going👍🏻

  • @affanarif750
    @affanarif750 ปีที่แล้ว

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

  • @twndomn
    @twndomn 3 ปีที่แล้ว +1

    Music too loud

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      Very sorry for that...

  • @nagendranfriends3153
    @nagendranfriends3153 4 ปีที่แล้ว +1

    Please don't copy and paste through Git . You are not explaining each and every line . Difficulty for understanding by Beginners

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      Very sorry to hear that...and indeed, I'm not copying and pasting a single line of code from GitHub in this video, I try to explain every line of code in detail...Anyways, sorry to hear that, I would definitely improve my side in future videos, if anything goes wrong😊

    • @nagendranfriends3153
      @nagendranfriends3153 4 ปีที่แล้ว +1

      @@CodeBand one request please . I don't know Ajax and JQuery . I am trying to make a Chained Dropdown list . Is there is any other possible way . I like to keep it in Registration page . Is it possible I.e Custom Registration

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      @@nagendranfriends3153 It's almost impossible to implement chained dropdown in Django without knowing AJAX and/or jQuery. You might need to check for Django packages that might do this for you without directly messing with AJAX. Check this website for Django packages:
      djangopackages.org/

    • @nagendranfriends3153
      @nagendranfriends3153 4 ปีที่แล้ว +1

      @@CodeBand oh , then please explain about the Ajax and JQuery . And why they are used . Please in a short video. Because of not having a bit knowledge about them it is difficult to use it . Please explain

    • @CodeBand
      @CodeBand  4 ปีที่แล้ว +1

      @@nagendranfriends3153 You can find quick crash courses of jQuery and AJAX in YTB. There are a lot of videos out there!😊

  • @hidayathidayat4469
    @hidayathidayat4469 3 ปีที่แล้ว +2

    the music is unnecessary

    • @CodeBand
      @CodeBand  3 ปีที่แล้ว +1

      Very sorry for that...