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

  Рет қаралды 11,410

BugBytes

BugBytes

Күн бұрын

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 ай бұрын
Playlist link: kzbin.info/www/bejne/e6SlonyQordli8U
@treborsol
@treborsol 11 ай бұрын
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 ай бұрын
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!
@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.
@bugbytes3923
@bugbytes3923 Ай бұрын
Thanks a lot!
@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 ай бұрын
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!
@alfredoa334
@alfredoa334 8 ай бұрын
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
@LoumiGueye
@LoumiGueye 2 ай бұрын
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!
@khunjohn1054
@khunjohn1054 11 ай бұрын
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!
@krugergaming-yt8121
@krugergaming-yt8121 Ай бұрын
Man thank you, this video clarified my doubt in M2M in django
@bugbytes3923
@bugbytes3923 Ай бұрын
Great to hear, thanks for sharing!
@auraSinhue
@auraSinhue 7 ай бұрын
Great video! Clearly explained :)
@bugbytes3923
@bugbytes3923 7 ай бұрын
Thanks a lot!
@user-xu7jz4li7e
@user-xu7jz4li7e 11 ай бұрын
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 !
@bjdollcoloredpencil3273
@bjdollcoloredpencil3273 5 ай бұрын
Thank you so much:). That is a very good tutorial:)
@bugbytes3923
@bugbytes3923 5 ай бұрын
Thanks so much!
@Aerish369
@Aerish369 3 ай бұрын
Thank you so much.
@bugbytes3923
@bugbytes3923 3 ай бұрын
You’re welcome! Thanks for watching!
@aashayamballi
@aashayamballi 11 ай бұрын
Thank you!
@bugbytes3923
@bugbytes3923 11 ай бұрын
You're welcome, thanks for watching!
@khalilbenmeziane8836
@khalilbenmeziane8836 11 ай бұрын
thank you bro
@bugbytes3923
@bugbytes3923 11 ай бұрын
Thanks for watching!
@TomOhle1
@TomOhle1 11 ай бұрын
Great content
@bugbytes3923
@bugbytes3923 11 ай бұрын
Thanks a lot!
@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?
@Septumsempra8818
@Septumsempra8818 11 ай бұрын
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 ай бұрын
Great suggestion, I'll add that to the list, thank you!
@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 4 ай бұрын
Thanks, will look into those!
@frameff9073
@frameff9073 11 ай бұрын
thank
@bugbytes3923
@bugbytes3923 11 ай бұрын
You're welcome!
@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
@killer_hok5757
@killer_hok5757 Ай бұрын
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 ?
@HeisenbergHK
@HeisenbergHK 4 ай бұрын
What is the link to the previous video?
@bugbytes3923
@bugbytes3923 4 ай бұрын
It’s on this playlist here: kzbin.info/aero/PL-2EBeDYMIbQXKsyNweppuFptuogJe2L-
@asgeralia8802
@asgeralia8802 9 ай бұрын
Superb and awesome but i want your email bcz i hv lot of doubts in autocomplete
Русалка
01:00
История одного вокалиста
Рет қаралды 7 МЛН
Does size matter? BEACH EDITION
00:32
Mini Katana
Рет қаралды 19 МЛН
Зачем он туда залез?
00:25
Vlad Samokatchik
Рет қаралды 2,9 МЛН
Django - F Expressions for database-level operations
20:36
BugBytes
Рет қаралды 4,1 М.
Django ORM Deep Dive - Introduction to Databases & SQL
29:18
BugBytes
Рет қаралды 17 М.
Django - select_for_update() function / Locking Database Rows
23:36