On Tue, Jul 03, 2007 at 07:34:55AM -0000, Johann C. Rocholl wrote: > > Often I want to preload just some foreign keys, not all of them as > select_related() does. Other people seem to need this feature too: > http://groups.google.com/group/django-developers/browse_thread/thread/e5e0de59e8304bcd/bb93410289bc19b7 > http://code.djangoproject.com/ticket/3275 > > My solution: I have written a function that preloads only the > requested foreign keys, and only for the objects that are already > selected. My implementation is available here: > http://trac.browsershots.org/browser/branches/shotserver-django/shotserver04/common/preload.py > > My implementation has one advantage over the field parameter for > select_related: you can pass a query set that you already have, and > then you don't need any database queries again.
You might want to take a look at ticket 17 also, since it provides similar capabilities automatically- if that particular pk was already pulled, it grabs the instance in memory instead of hitting the backend again, and generating a new model instance. ~harring
pgpS7bjlXdCxO.pgp
Description: PGP signature
