Django ManyToManyFields and Through-Models for many-to-many relationships

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ค. 2024
  • In this video, we'll look at many-to-many relations in Django. We'll see how to add a ManyToManyField on a Django model, and how to use that field to query for related objects with the ManyRelatedManger and functions such as add(), remove(), all(), set() and clear().
    We'll also look at junction tables in the database, created for many-to-many relationships, and will see how Django creates these implicitly, and how we can explicitly add extra data to these tables via through models.
    📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
    00:00 Intro
    01:36 ManyToManyField in Django
    04:26 Junction Tables for ManyToManyFields in Django
    06:27 Querying ManyToManyFields in Django
    19:00 Customising ManyToManyFields with the through argument (through models)
    ☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
    To support the channel and encourage new videos, please consider buying me a coffee here:
    ko-fi.com/bugbytes
    ▶️ Full Playlist:
    • Django ORM Deep Dive
    𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
    📖 Blog: bugbytes.io/posts/
    👾 Github: github.com/bugbytes-io/django...
    🐦 Twitter: / bugbytesio
    📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
    Many-to-Many Relationships: docs.djangoproject.com/en/4.2...
    Extra Fields on M2M Relationships: docs.djangoproject.com/en/4.2...
    Associative Entity: en.wikipedia.org/wiki/Associa...
    #python #django #webdevelopment #database #sql

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

  • @bugbytes3923
    @bugbytes3923  3 หลายเดือนก่อน +2

    Playlist link: th-cam.com/video/EsBqIZmR2Uc/w-d-xo.html

  • @krugergaming-yt8121
    @krugergaming-yt8121 27 วันที่ผ่านมา

    Man thank you, this video clarified my doubt in M2M in django

    • @bugbytes3923
      @bugbytes3923  26 วันที่ผ่านมา

      Great to hear, thanks for sharing!

  • @treborsol
    @treborsol 11 หลายเดือนก่อน +5

    Thank you. This was the best overview of the manytomany relation options in Django I have seen so far. Perhaps in a next version you can elaborate on the 'related_name' option and how to use that?

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

      Thanks a lot! I'll try and elaborate on related name in future, too.

  • @seydinaoumarsamabaly1806
    @seydinaoumarsamabaly1806 11 หลายเดือนก่อน +4

    Just aww, I really can say that I've well understood the M2M concept with this one 🙌🏾. Thank you mate !

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

      Thanks a lot!

  • @alfredoa334
    @alfredoa334 8 หลายเดือนก่อน +2

    Impressive!!! By far, the best video of the ManyToMany relations in Django!!! Thank you very much.

    • @bugbytes3923
      @bugbytes3923  8 หลายเดือนก่อน

      Thanks a lot, I’m delighted to hear that! Thanks for watching!

    • @alfredoa334
      @alfredoa334 8 หลายเดือนก่อน

      Thank you for posting. I am glad I found your channel. Great content!!! You have one more subscriber. I hope you channel keeps growing. Best regards.@@bugbytes3923

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

    This is supper man thanx for creating this series and also other series and videos you have provided that's great content man I have benefited and learnt a lot from you keep up the good work, Thnax once again.

  • @mikedodds9926
    @mikedodds9926 8 หลายเดือนก่อน

    Excellent explanation ! came here to understand M2M queries and achieved that plus so much more ! Off to put into practice now ...

  • @Pedro_Nora
    @Pedro_Nora 8 หลายเดือนก่อน +1

    Thank you, guy! This is a video that I will watch many times. It has a lot of good information and clear explanations!

    • @bugbytes3923
      @bugbytes3923  8 หลายเดือนก่อน

      Thanks a lot Pedro! Glad it is useful, and thank you for watching!

  • @LoumiGueye
    @LoumiGueye 2 หลายเดือนก่อน +1

    Bruh you saved me so much time in my buiding project. Keep the good work! Awesome

    • @bugbytes3923
      @bugbytes3923  2 หลายเดือนก่อน

      Glad to hear it dude! Good luck with your project and thanks!

  • @auraSinhue
    @auraSinhue 7 หลายเดือนก่อน +1

    Great video! Clearly explained :)

    • @bugbytes3923
      @bugbytes3923  7 หลายเดือนก่อน

      Thanks a lot!

  • @user-xu7jz4li7e
    @user-xu7jz4li7e 11 หลายเดือนก่อน +2

    Saving this for the weekend. Thank you!

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

      Thank you!

    • @user-xu7jz4li7e
      @user-xu7jz4li7e 3 หลายเดือนก่อน

      @@bugbytes3923 Can you please do a follow-up video and expand on how the ManyToManyFields and the extra fields in the Through-Models can be implemented in Forms and Views? Thank you and have a great weekend!

  • @aV5d9nlUBQ9
    @aV5d9nlUBQ9 6 หลายเดือนก่อน

    Thanks, man! A great video that helped me a lot

    • @bugbytes3923
      @bugbytes3923  6 หลายเดือนก่อน

      Thanks a lot !

  • @khunjohn1054
    @khunjohn1054 11 หลายเดือนก่อน +1

    As usual great content. One thing is in the admin panel if you are using inlines, that the model require the related_name..through as the end as in "model = Restaurant.staff.through" if you want to list all staff members under each restaurant in a stacked or tabular inline. This will also display the through table fields. Pretty nifty.

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

      Thank you, and nice suggestion there - I should have added it!

  • @bjdollcoloredpencil3273
    @bjdollcoloredpencil3273 5 หลายเดือนก่อน

    Thank you so much:). That is a very good tutorial:)

    • @bugbytes3923
      @bugbytes3923  4 หลายเดือนก่อน

      Thanks so much!

  • @aashayamballi
    @aashayamballi 11 หลายเดือนก่อน +1

    Thank you!

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

      You're welcome, thanks for watching!

  • @Aerish369
    @Aerish369 2 หลายเดือนก่อน +1

    Thank you so much.

    • @bugbytes3923
      @bugbytes3923  2 หลายเดือนก่อน +1

      You’re welcome! Thanks for watching!

  • @khalilbenmeziane8836
    @khalilbenmeziane8836 11 หลายเดือนก่อน +1

    thank you bro

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

      Thanks for watching!

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

    Great content

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

      Thanks a lot!

  • @frameff9073
    @frameff9073 11 หลายเดือนก่อน +1

    thank

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

      You're welcome!

  • @user-ll4pv3yd5v
    @user-ll4pv3yd5v 4 หลายเดือนก่อน

    hello, tanks for this course, its so useful for me
    please record a course about deep dive in view
    and please record a course to customizing admin panel template and add some function to admin panel

    • @bugbytes3923
      @bugbytes3923  3 หลายเดือนก่อน

      Thanks, will look into those!

  • @Septumsempra8818
    @Septumsempra8818 11 หลายเดือนก่อน +2

    In your next HTMX x Alpine.js video could you cover passing data between htmx and Alpine components. Eg. How do I change an HTMX request based on x-data state?
    I saw the "htmx.process()" method, but It's not so clear.
    Keep up the great work
    🇿🇦

    • @bugbytes3923
      @bugbytes3923  11 หลายเดือนก่อน +2

      Great suggestion, I'll add that to the list, thank you!

  • @rakeshmali1727
    @rakeshmali1727 3 หลายเดือนก่อน

    Hey, great video.
    Just one question, at 17:40, can't we just add another `staffs = ManyToManyField(Staff)` in Restaurant model as well?

  • @killer_hok5757
    @killer_hok5757 27 วันที่ผ่านมา

    hi in this case we have 2 table and a many to many relationship , what if have 3 table and and a many to many relationship , how can i write many to many field and where ?

  • @asgeralia8802
    @asgeralia8802 9 หลายเดือนก่อน

    Sir i want autocomplete with out foreignkey in list need to display db columns like id, description, shortname, alias and etc i want to get any one according requirement like some time i wl get description or shortname or id

  • @HeisenbergHK
    @HeisenbergHK 4 หลายเดือนก่อน +1

    What is the link to the previous video?

    • @bugbytes3923
      @bugbytes3923  4 หลายเดือนก่อน

      It’s on this playlist here: th-cam.com/play/PL-2EBeDYMIbQXKsyNweppuFptuogJe2L-.html

  • @asgeralia8802
    @asgeralia8802 9 หลายเดือนก่อน

    Superb and awesome but i want your email bcz i hv lot of doubts in autocomplete