mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
[2.0.x] Fixed #29032 -- Fixed an example of using expressions in QuerySet.values().
Backport of 7fbb1bd00d
from master
This commit is contained in:
parent
fbe7c8f413
commit
c881c4f1f8
1 changed files with 4 additions and 4 deletions
|
@ -540,10 +540,10 @@ within the same ``values()`` clause. If you need to group by another value,
|
|||
add it to an earlier ``values()`` clause instead. For example::
|
||||
|
||||
>>> from django.db.models import Count
|
||||
>>> Blog.objects.values('author', entries=Count('entry'))
|
||||
<QuerySet [{'author': 1, 'entries': 20}, {'author': 1, 'entries': 13}]>
|
||||
>>> Blog.objects.values('author').annotate(entries=Count('entry'))
|
||||
<QuerySet [{'author': 1, 'entries': 33}]>
|
||||
>>> Blog.objects.values('entry__authors', entries=Count('entry'))
|
||||
<QuerySet [{'entry__authors': 1, 'entries': 20}, {'entry__authors': 1, 'entries': 13}]>
|
||||
>>> Blog.objects.values('entry__authors').annotate(entries=Count('entry'))
|
||||
<QuerySet [{'entry__authors': 1, 'entries': 33}]>
|
||||
|
||||
A few subtleties that are worth mentioning:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue