diff options
| author | Iván Camilo Triviño López <25367296+IvanTrivino@users.noreply.github.com> | 2022-08-29 23:03:53 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-08-30 06:06:03 +0200 |
| commit | 29fac6b6160ffd9c6e9b37ed2ed964d292575545 (patch) | |
| tree | 7848df7827388cea2331fdb2d0ec87e002a341e9 | |
| parent | e992703e07940458443897ae8c4b06bb1b8f5049 (diff) | |
[4.1.x] Fixed #33958 -- Added imports to examples in "Expressions can reference transforms" section.
Backport of 411a6ec93a9b21e5ed1e9fc05b34f021288cd10c from main
| -rw-r--r-- | docs/topics/db/queries.txt | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index d256545453..6deeec5037 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -701,15 +701,18 @@ Django supports using transforms in expressions. For example, to find all ``Entry`` objects published in the same year as they were last modified:: + >>> from django.db.models import F >>> Entry.objects.filter(pub_date__year=F('mod_date__year')) To find the earliest year an entry was published, we can issue the query:: + >>> from django.db.models import Min >>> Entry.objects.aggregate(first_published_year=Min('pub_date__year')) This example finds the value of the highest rated entry and the total number of comments on all entries for each year:: + >>> from django.db.models import OuterRef, Subquery, Sum >>> Entry.objects.values('pub_date__year').annotate( ... top_rating=Subquery( ... Entry.objects.filter( |
