Impossible to reproduce example in the documentation of Queryset.values()

16 views
Skip to first unread message

Joseph Lucas

unread,
Jan 17, 2018, 11:37:23 AM1/17/18
to django...@googlegroups.com, Arnaud Peloquin
Hi,

We were not able to reproduce an example described in Django's documentation, concerning the value() method of Queryset.


>>> from django.db.models import Count
>>> Blog.objects.values('author', entries=Count('entry'))
<QuerySet [{'author': 1, 'entries': 20}, {'author': 1, 'entries': 13}]>

When executing above lines with the fixtures described in the docs, we get the following error:

django.core.exceptions.FieldError: Cannot resolve keyword 'author' into field. Choices are: entries, entry, id, name, tagline

This second example from the documentation doesn't seem to work either:
 
>>> Blog.objects.values('author').annotate(entries=Count('entry'))
<QuerySet [{'author': 1, 'entries': 33}]>

Did we miss something ?
Is the django documentation accurate here ? We wonder how a Blog object could have an 'author' field, given its model definition.

Please find attached a minimal project with unittests reproducing these issues.

Sincerely,

Joseph Lucas
Arnaud Peloquin

bug_django_annotate.tar.gz

Tim Graham

unread,
Jan 17, 2018, 1:55:02 PM1/17/18
to Django users
Confirmed. I opened a bug report: https://code.djangoproject.com/ticket/29032.
Reply all
Reply to author
Forward
0 new messages