Thanks Tim,

This is a great addition, maybe I can do what I want with that (I'll have 
to think about it) but what I was hoping for is more within the lookup 
string itself.  A simple example (this is simplified from a stack overflow 
question I posted on this topic before I started poking around in the 
internals) would be if you have a Car model with options JSONField (using 
postgres).  Consider the two queries:

> Car.objects.filter(options__color='red')
> Car.objects.values('options__color')

The filter works because the lookup parser in build_filter calls 
get_transform, which knows how to key into the JSON field.  But the second 
query gives a join error because there is no call to get_transform in 
Query.add_fields (so "color" is assumed to be a relation).  I can get 
around this with an annotation and some RawSQL, but it's not very clean 
compared to making use of get_transform.

Thanks again for looking at this!
-Rishi.

On Thursday, August 18, 2016 at 6:44:25 PM UTC-7, Tim Graham wrote:
>
> I merged support for expressions in values() a few hours ago: 
> https://github.com/django/django/commit/39f35d4b9de223b72c67bb1d12e65669b4e1355b
>
> If that doesn't meet your needs, can you give an idea of what the QuerySet 
> you want would look like?
>
> On Thursday, August 18, 2016 at 5:10:41 PM UTC-4, Rishi Graham wrote:
>>
>> I noticed that the jsonb field indexing in postgres which is so handy in 
>> filtering does not seem to extend to calls to values().  After digging 
>> around a bit, it seems that sql.query.get_transform() is only called when 
>> building a filter, but not when adding fields for a values call. 
>>
>> Using transforms in both places was mentioned as part of the now closed 
>> feature request, #21863, which states that the "values() call will use 
>> always get_transform() so .values('hstorefield__exact') will work 
>> correctly”.   This was a little confusing because values does not use 
>> “lookup”, which seems to refer only to the comparison type extension in the 
>> filter string, but I am still relatively new to django so maybe I’m missing 
>> something. 
>>
>> I don’t see evidence of any further discussion of the effect on values 
>> calls.  Anyone know if this was on purpose, or just an oversight? 
>>
>> Thanks, 
>> -Rishi.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a70a4f35-6482-46f1-958f-e9fc6d8d93c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to