Тёмный

Django Aggregation & Annotation / values() and values_list() functions 

BugBytes
Подписаться 27 тыс.
Просмотров 8 тыс.
50% 1

In this video, we look at aggregation and annotation in Django - how to summarize and aggregate data to get summary statistics and insights into your application data.
We look at how to annotate models with additional data, using the annotate() function, and how to pair this with the values() function to create specific groupings of data that can then be analysed and aggregated.
We also look at the values() and values_list() functions in general in this video.
📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
01:37 values function on Django QuerySets
06:41 Transforming values with database functions
08:25 Getting Foreign Key data with values() function
10:47 values_list() function on Django QuerySets
13:48 Aggregating values in Django with aggregate() method
24:18 Annotating models in Django with annotate() method
☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
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
📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
Django Aggregation: docs.djangoproject.com/en/4.2...
Aggregate with values(): docs.djangoproject.com/en/4.2...
Annotate function: docs.djangoproject.com/en/4.2...
Aggregate function: docs.djangoproject.com/en/4.2...
values() function: docs.djangoproject.com/en/4.2...
values_list() function: docs.djangoproject.com/en/4.2...
#python #django #webdevelopment #database #sql

Опубликовано:

 

30 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 51   
@bugbytes3923
@bugbytes3923 2 месяца назад
Playlist link: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-EsBqIZmR2Uc.html
@rhysjesett99
@rhysjesett99 10 месяцев назад
These are genuinely some of the most helpful tutorials on the Internet. No fluff, just constant gold.
@bugbytes3923
@bugbytes3923 10 месяцев назад
Wow, thanks a lot! Delighted to hear that!
@khunjohn1054
@khunjohn1054 10 месяцев назад
As usual, great tutorial. I hope that in the next video you include OuterRef and Subquery. This is a more advanced topic, but it packs a ton of functionality. ie. Let's say you have a company with many offices and one of those offices is market as the HQ. With OuterRef and Subquery, you can annotate the company address from the specific office in the many to one related table marked as the HQ and also aggregate the total amount of employees as a Sum of each office.
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thank you! I'll cover these topics very soon - not the next video but the one after, I think. But yeah, will definitely cover it!
@seydinaoumarsamabaly1806
@seydinaoumarsamabaly1806 10 месяцев назад
I just want to thank you Master 🙌🏾before I finish watching the tutorial !
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thanks as always! 😄
@codedjango
@codedjango 10 месяцев назад
Very nice explanation on aggregate and annotate.....thank you so much
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thanks very much!
@farzadmf
@farzadmf 10 месяцев назад
SUPER high quality video as always; great job!
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thanks a lot 🙏
@robhafemeister3100
@robhafemeister3100 10 месяцев назад
Great video! you explained in less than an hour what probably took me a week to learn on my own awhile back. Love it!
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thanks a lot Rob, much appreciated as always!
@thokozanindlovu1939
@thokozanindlovu1939 5 месяцев назад
Another brilliant video. thank you
@bugbytes3923
@bugbytes3923 5 месяцев назад
Thanks a lot!
@Peterstavrou
@Peterstavrou 10 месяцев назад
This series has been incredible!
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thanks a lot Peter!
@user-xc2me6zh2k
@user-xc2me6zh2k 9 месяцев назад
awesome content Mate!! I learned many new concepts in this video and will try to apply in my projects too 😁
@bugbytes3923
@bugbytes3923 9 месяцев назад
Awesome, thanks a lot, glad you liked the video!
@vaibhavbijapur6037
@vaibhavbijapur6037 6 месяцев назад
bro you deserve more followers
@bugbytes3923
@bugbytes3923 6 месяцев назад
Thanks man!
@repotranstech9614
@repotranstech9614 10 месяцев назад
Thanks 👍 for this tutorial.I have a microfinance project that will require this.
@bugbytes3923
@bugbytes3923 10 месяцев назад
Hope the video will help! 👍
@DhavalAhir10
@DhavalAhir10 8 месяцев назад
Amazing every concept clear. Love from India bro. ✌️
@bugbytes3923
@bugbytes3923 8 месяцев назад
Thanks a lot bro! Glad it was clear and greetings from Scotland!
@user-ib9dv3pr9b
@user-ib9dv3pr9b 10 месяцев назад
Thanks for great videos
@bugbytes3923
@bugbytes3923 10 месяцев назад
You’re welcome, thanks a lot for watching!
@user-gi7ei7rm4x
@user-gi7ei7rm4x 10 месяцев назад
Nice plants as well as the video
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thanks a lot! 🪴😄
@Niki-ue6fk
@Niki-ue6fk 3 месяца назад
Thanks !!
@bugbytes3923
@bugbytes3923 3 месяца назад
Thanks for watching!
@priyanshvatsal9791
@priyanshvatsal9791 Месяц назад
So much useful information in just one video. Thanks
@bugbytes3923
@bugbytes3923 Месяц назад
Glad to hear it, thanks a lot for watching and commenting!
@Septumsempra8818
@Septumsempra8818 10 месяцев назад
Great tutorial. Any caching vids coming?
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thanks! Yes, I'll be doing stuff with Django + Redis in the near future.
@firstandlast4435
@firstandlast4435 Месяц назад
A little recap: Annotate by itself (without values()) doesn't do grouping even with use of aggregate functions (which just duplicate argumented field in such case); We use annotate() with values() and we don't use it with only() (at least my tests proved last as useless); We can start from both child and parent Model and get the same result So this: Books.objects.values_list("author__firstname", "author__lastname").annotate( total=Count("id") ) And that: q = Author.objects.values_list("firstname", "lastname").annotate( total=Count("books") ) will do the same (p.s. "books" in the last statement refers to "related_query_name" specified in ForeignKey field of the "Books" model );
@frameff9073
@frameff9073 10 месяцев назад
thank
@bugbytes3923
@bugbytes3923 10 месяцев назад
Thanks for watching!
@paulwanjohi2537
@paulwanjohi2537 2 месяца назад
Incredible. That was so helpful. Thank you man👊
@bugbytes3923
@bugbytes3923 2 месяца назад
Thanks a lot man! Glad it helped.
@anatoliyloboda4601
@anatoliyloboda4601 5 месяцев назад
It's a very interesting and important part of working with DB. Thank you for sharing!!!
@azhariqbal3658
@azhariqbal3658 4 месяца назад
Is there any package you use for runscript this is very useful for testing queries
@bugbytes3923
@bugbytes3923 4 месяца назад
It’s part of django-extensions which I always add to django projects
@Yarkanlaki
@Yarkanlaki 2 месяца назад
I wonder why aggregation results always is too big.? Comapre to use for loop
@user-jd9fc7to4c
@user-jd9fc7to4c 8 месяцев назад
hi, do you have solution for Like: Multiple table field Sum calculation from parent model ---------- to get stock qty each product (stock qty= purchase_qty - purchase_return_qty - sales_qty + sales_qty )
@wihlarkop
@wihlarkop 10 месяцев назад
can you make tutorial how to use async queryset on django 4?
@bugbytes3923
@bugbytes3923 10 месяцев назад
Yes, definitely!
@firstandlast4435
@firstandlast4435 Месяц назад
What I dislike about youtube is that there's a need in comments in order to promote a channel, it might be ok in some cases but when it's about education I actually wanna see some related to subject discussions on top instead of "thanks author you are so great"... Anyway what I failed to understand is when annotate is used to add extra field to query set and when to group by fields and the similar about values. As it does return dictionaries like? Then why can we do things like ModelName.objects.values('smth').annotate(Agregate func) and then use functions like order by to it. Don't we need Django specific query sets to use those functions, or we can use it to any dictionary?
@bugbytes3923
@bugbytes3923 Месяц назад
The annotate() function will add the annotated field to each object in the queryset. Importantly, annotate returns a queryset, so you can chain other methods like values() and order_by(), etc. The aggregate() function, on the other hand, returns a dictionary containing all the aggregations passed to the function. Queryset methods don’t work on dictionaries, so chaining additional methods like order_by() won’t work.
@pakeffendi5061
@pakeffendi5061 6 месяцев назад
# fungction to get one cctv location and past it to leaflet map def Cctvlist(request, id): # get cctv category cctvs = get_object_or_404(Daftarcctv, id = id) # show all cctv location in cctv category cctv = cctvs.cctvdetail_set.all() # lopping all cctv location for i in cctv: # get one cctv location from i looping showloc = Cctvlocation.objects.get(pk=i) # i want to get cctv location row to past in json format # and get values lat, long from varible "showloc" # BUT ALWAYS FAIL, PLEASE SHOW ME A SOLUTION cctvsloc = list(Cctvlocation.objects.values('latitude', 'longitude')[:100]) print(cctvsloc) return render(request, 'cctvkorem/daftarcctv.html', {'cctvs':cctvs, 'cctv':cctv, 'showloc':showloc })
Далее
Django - F Expressions for database-level operations
20:36
Solving one of PostgreSQL's biggest weaknesses.
17:12
Просмотров 176 тыс.
Build an SQL Agent with Llama 3 | Langchain | Ollama
20:28
Django Database Transactions / atomic() function
34:15
Просмотров 4,6 тыс.