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 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