Hey,

On Fri, Jul 17, 2009 at 5:06 PM, Miriam<magol...@gmail.com> wrote:
>
> There currently is no way in Django to pre-fetch one-to-many and/or
> many-to-many relationships, right?
>
> There's select_related, which will pre-fetch FK or one-to-one, which
> is great, but not sufficient.
>
> Suppose I am fetching a list of Blog posts and I want to pre-fetch the
> Comments for each of these posts? There's no way to do that in
> Django.
>
> I was looking through the tickets at code.djangoproject.com and I
> didn't see anything about this.
>
> Does anyone know if this feature is planned for sometime down the
> road? Anyone have a work-around or a patch or anything. This is
> supremely irritating.
>

I have implemented prefetching (I've choosen the name 'prefilling',
but prefetching might be more appropriate) for a CMS I'm working on;
you can find the code here:

<http://github.com/matthiask/feincms/blob/426e1b62c3df89a990f5f569abc5ef53bf38e0e7/feincms/utils.py>

I can do something like that to prefetch authors (m2m), images and
richtext elements (both reverse foreign keys) for a list of blog posts
for example. It wont work for django.contrib.comments though, since
the comments model uses generic relations, and I've not implemented
prefetching for those yet.


Matthias
Maybe it will inspire someone to create

> Miriam
>
> >
>



-- 
Matthias Kestenholz
Konzept & Programmierung

FEINHEIT GmbH
Dienerstrasse 15
CH-8004 Zürich

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