Django ORM - Updating and Deleting QuerySets / ForeignKey on_delete behaviour

preview_player
Показать описание
In this video, we look at how to update and delete models and querysets in Django.

For UPDATES, we'll look at updating an individual model (representing a DB row), and will see how to use the "update_fields" argument to the model save() method. We'll also look at the Django ModelState object's "adding" property. Finally, we'll see how to update an entire QuerySet, and set a value across that QuerySet.

For DELETES, we'll see how to delete individual models, as well as entire QuerySets of models. We'll also look at how the ForeignKey on_delete argument works during deletes, paying particular attention to the models.CASCADE and models.SET_NULL options.

📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
00:48 Updating Django model instances
03:18 Passing updated fields to model save() method with update_fields argument
03:52 Checking whether model is added or updated in model save() method
06:59 Updating a QuerySet of records with queryset update() method
09:36 Filtering QuerySet with a startswith lookup in Django
15:22 Deleting model instances with model delete() function
16:17 Effect of CASCADE on_delete parameter on foreign key
20:20 Effect of SET_NULL on_delete parameter for foreign keys
21:34 Django QuerySet delete() method to remove multiple objects

☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:

▶️ Full Playlist:

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:

#python #django #webdevelopment #database #sql
Рекомендации по теме
Комментарии
Автор

Thank you alot sir, please make a playist about dajngo signals and continue with django rest framework, You are the best !

MuhammedKamaal
Автор

Love this waited a month for this series 😅 Yes want to learn about signals.

Davidkiania
Автор

Thank you so much for this amazing playlist 🎉😊

open-source
Автор

Saved! Gonna watch this during the weekend when I have more time. Thanks!

xujzlie
Автор

Cool video as always.On top of that can you add functionality where you check multiple checkboxes and update with htmx and Django querysrt.

repotranstech
Автор

Yes, teach about Signals on Django. your work is really great and helpful. Keep it up!

muokinzangi
Автор

Much obliged!! You explain everything in such simple detail and it's been VERY helpful!! THANK you!!

MostafaHammad-wemz
Автор

Excellent series! Signals would be so helpful! Great channel :)

iwswordpress
Автор

Thanks again for this series, very helpful

saptechstuff
Автор

I let you know I'm interested in you making a video about signals 😁

adhd_arti
Автор

Thanks so much man. Had an interesting observation in my SQL - My .save(update_fields=...) executed 50% SLOWER than my regular .save( ) ! Is this expected or is something wrong with my sqllite? Intuitively, I thought the opposite would happen.

thinkingcitizen
Автор

I've noticed that by default most people simply use the .save() method when updating single fields rather than specifying specific fields such as Is there much performance improvement specifying specific fields or should we stick to .save() for ease?

Peterstavrou