Oh, and list() was required ;-)

On Thursday, 26 July 2012 20:44:45 UTC+1, akaariai wrote:
>
> On 26 heinä, 19:12, Sencha <mich...@d3i.com> wrote: 
> > I want to prefetch related data (ideally through the 
> prefetch_related()method), however I need to use the 
> > raw() mapper method that will map a custom query (complicated table 
> joins 
> > to filter my query properly) to my model. However when I try this I get: 
> > 
> > AttributeError: 'RawQuerySet' object has no attribute 'prefetch_related' 
> > 
> > Is there any way I can achieve the prefetching when using 
> > Model.objects.raw()? 
> > 
> > Many thanks! 
>
> There is no direct way. However, you could try this (completely 
> untested, and not part of public api): 
>
>     from django.db.models.query import prefetch_related_objects 
>     raw_qs = list(raw_qs) # this line maybe not needed... 
>     prefetch_related_objects(raw_qs, ['a_related_lookup', 
> 'another_related_lookup', ...]) 
>
>  - Anssi 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/pokK8uRCCFcJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to