MENU

Fun & Interesting

Django ORM - Querying and Creating Records / Working with Foreign Keys

BugBytes 18,605 lượt xem 1 year ago
Video Not Working? Fix It Now

In this video, we'll cover ways to query databases with the Django ORM, and ways to create data with the ORM.

We'll look at a number of techniques, including the following methods:
- Model.objects.all()
- Model.objects.filter() / Model.objects.exclude()
- Model.objects.first() / Model.objects.last()
- Model.objects.create() / Model.objects.get_or_create()

We'll also look at how to create and query Foreign Key relations in Django.

▶️ Full Playlist:
https://www.youtube.com/playlist?list=PL-2EBeDYMIbQXKsyNweppuFptuogJe2L-

📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
00:55 django-extensions runscript command
02:21 Creating records by instantiating and saving Django models
07:07 Querying Data - Getting All Rows From a Table
09:41 Querying First Row with Model.objects.first()
11:05 Indexing into Django QuerySets
11:55 Creating Records with Model.objects.create()
13:51 Counting records with Model.objects.count()
15:15 Querying Foreign Keys in Django
18:49 Filtering records with Model.objects.filter()
21:18 Filtering records with Model.objects.exclude()
22:16 Updating existing records with model save() method
24:37 Querying related records in Django ORM
26:20 Querying reverse relations in Django
31:22 Getting OR creating data with Model.objects.get_or_create()

☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
https://ko-fi.com/bugbytes

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: https://bugbytes.io/posts/
👾 Github: https://github.com/bugbytes-io/
🐦 Twitter: https://twitter.com/bugbytesio

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
Django-extensions runscript: https://django-extensions.readthedocs.io/en/latest/runscript.html
Django filter(): https://docs.djangoproject.com/en/4.2/ref/models/querysets/#filter
Django - Following Relations Backward: https://docs.djangoproject.com/en/4.2/topics/db/queries/#following-relationships-backward

#django #python #webdevelopment #database

Comment