That's absolutely perfect, works like a charm! Thank you very much for the insight.
On Thursday, 26 July 2012 20:44:45 UTC+1, akaariai wrote: > > On 26 heinä, 19:12, Sencha <[email protected]> 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/-/XHw_hG4RdPcJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

