So I have this loop:

for t in ts.prefetch_related('u__v_set'):
    bla = t.x
    ...

Running this code in debugsqlshell I see three (constant amount in general) 
sql statements:

   - one getting all t's
   - second one getting related u's
   - third one getting related v's

Now, in the same loop I would like to refer to some attribute of v (that 
was the reason I used prefetch_related). If I do it like this:

 ble = ','.join([item for item in map(lambda x: x[0], 
t.u.all().values_list('v__some_attribute')) if item])

the cash is invalidated and new sql is produced for each iteration of t.

Another try:

ble = ','.join([v.some_attribute for v in reduce(lambda x, y: x|y, 
[us.v_set.all() for us in t.u.all()]) if v.some_attribute])

this also invalidates cash. So how can I use this prefetched values at all?

-- 
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 http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to