Fixed #1548 -- Improved caching of related objects, so when clist = poll.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
This commit is contained in:
parent
82df62b545
commit
1edef8ede9
|
@ -1176,7 +1176,18 @@ def method_get_related(method_name, rel_mod, rel_field, self, **kwargs):
|
||||||
else:
|
else:
|
||||||
kwargs['%s__%s__exact' % (rel_field.name, rel_field.rel.to.pk.name)] = getattr(self, rel_field.rel.get_related_field().attname)
|
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)
|
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.
|
# Handles adding related objects.
|
||||||
# Example: Poll.add_choice()
|
# Example: Poll.add_choice()
|
||||||
|
|
Loading…
Reference in New Issue