filmov
tv
Django ORM - Updating and Deleting QuerySets / ForeignKey on_delete behaviour
Показать описание
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
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
Комментарии