[Answered ]-Why can't I use Django's field lookups in a values call?

1👍

https://docs.djangoproject.com/en/dev/ref/models/querysets/#values

I think you still need to use the extra query.

Field lookups

Field lookups are how you specify the meat of an SQL
WHERE clause. They’re specified as keyword arguments to the QuerySet
methods filter(), exclude() and get().

Django thinks you are trying to look up a field on a relationship field "date" when you use the double underscore with your values query.

👤dting

1👍

values is used to limit the SELECT statement and will map values directly to db field names. Django’s wizardry allowing you to use date__year=2000 as a filter() call doesn’t apply to values().

The best answer really depends on your needs / if you need a queryset or values.. but most people use values() as a shortcut to receive a dictionary mapping of a small number of keys.

It’s a shortcut that normally works! If it doesn’t, don’t hesitate to find any way to make the data work and move on..

[{'date__year': x.date.year, 'foo': 'bar'} for x in sum_qs.values('date', 'foo')]

Leave a comment