Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

magic-removal: Changed get_all_related_many_to_many_objects to use ca…

…ching. Refs #1186. Thanks, Russ

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1855 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2bc39d88e60ab9b9fa8e0b31e1af107c24cecfa6 1 parent b23b393
@adrianholovaty adrianholovaty authored
Showing with 12 additions and 8 deletions.
  1. +12 −8 django/db/models/options.py
View
20 django/db/models/options.py
@@ -166,14 +166,18 @@ def get_follow(self, override=None):
return follow
def get_all_related_many_to_many_objects(self):
- module_list = get_installed_model_modules()
- rel_objs = []
- for mod in module_list:
- for klass in mod._MODELS:
- for f in klass._meta.many_to_many:
- if f.rel and self == f.rel.to._meta:
- rel_objs.append(RelatedObject(self, klass, f))
- return rel_objs
+ try: # Try the cache first.
+ return self._all_related_many_to_many_objects
+ except AttributeError:
+ module_list = get_installed_model_modules()
+ rel_objs = []
+ for mod in module_list:
+ for klass in mod._MODELS:
+ for f in klass._meta.many_to_many:
+ if f.rel and self == f.rel.to._meta:
+ rel_objs.append(RelatedObject(self, klass, f))
+ self._all_related_many_to_many_objects = rel_objs
+ return rel_objs
def get_ordered_objects(self):
"Returns a list of Options objects that are ordered with respect to this object."
Please sign in to comment.
Something went wrong with that request. Please try again.