Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #1548 -- Improved caching of related objects, so when clist = p…

…oll.get_choice_list(), each choice in clist has its poll cache filled. Thanks, Ned Batchelder

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2574 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1edef8ede964e5dff962b8c9a52e65717dc81fe6 1 parent 82df62b
@adrianholovaty adrianholovaty authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 django/core/meta/__init__.py
View
13 django/core/meta/__init__.py
@@ -1176,7 +1176,18 @@ def method_get_related(method_name, rel_mod, rel_field, self, **kwargs):
else:
kwargs['%s__%s__exact' % (rel_field.name, rel_field.rel.to.pk.name)] = getattr(self, rel_field.rel.get_related_field().attname)
kwargs.update(rel_field.rel.lookup_overrides)
- return getattr(rel_mod, method_name)(**kwargs)
+ related = getattr(rel_mod, method_name)(**kwargs)
+
+ # Cache the 'self' object for backward links.
+ # Example: Each choice in Poll.get_choice_list() will have its poll cache filled.
+ # Pre-cache the self object, for following links back.
+ if method_name == 'get_list':
+ cache_name = rel_field.get_cache_name()
+ for obj in related:
+ setattr(obj, cache_name, self)
+ elif method_name == 'get_object':
+ setattr(related, rel_field.get_cache_name(), self)
+ return related
# Handles adding related objects.
# Example: Poll.add_choice()
Please sign in to comment.
Something went wrong with that request. Please try again.