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

preview_player
Показать описание
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:

▶️ Full Playlist:

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

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

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

These are genuinely some of the most helpful tutorials on the Internet.

No fluff, just constant gold.

rhysjesett
Автор

Never seen a tutorial so well explained...❤

gigi-hp
Автор

I have watched so many tutorials and yours is the best i have come across. Its detailed easy to understand and structured. Keep the good work up. Thanks

XzibiTP
Автор

Best series on Django advance topics. I have improved the performance of my project a lot. you are doing a great job creating a lot of value.

hemrajkaliraman
Автор

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.

khunjohn
Автор

Very nice explanation on aggregate and you so much

codedjango
Автор

I just want to thank you Master 🙌🏾before I finish watching the tutorial !

seydinaoumarsamabaly
Автор

Great video! you explained in less than an hour what probably took me a week to learn on my own awhile back. Love it!

robhafemeister
Автор

very helpful, that's exactly what I was looking for, thanks again bro !!

Rinpower
Автор

SUPER high quality video as always; great job!

farzadmf
Автор

Thanks 👍 for this tutorial.I have a microfinance project that will require this.

repotranstech
Автор

Amazing every concept clear.
Love from India bro. ✌️

DhavalAhir
Автор

So much useful information in just one video. Thanks

priyanshvatsal
Автор

awesome content Mate!! I learned many new concepts in this video and will try to apply in my projects too 😁

ShivaR-kb
Автор

Incredible. That was so helpful. Thank you man👊

paulwanjohi
Автор

It's a very interesting and important part of working with DB. Thank you for sharing!!!

anatoliyloboda
Автор

Great tutorial.
Any caching vids coming?

Septumsempra
Автор

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 );

firstandlast
Автор

In the Concat topic, what if a field's value were empty? Is there a way to pass a fallback value for it ?

abbasebadian
Автор

Is there any package you use for runscript this is very useful for testing queries

azhariqbal
join shbcf.ru