Fixed #14270 - related manager classes should be cached

Thanks to Alex Gaynor for the report and initial patch, and mrmachine for
more work on it.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16916 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Luke Plant 2011-09-30 10:41:25 +00:00
parent 2eadc418af
commit 5009e45dfe
4 changed files with 87 additions and 40 deletions

View file

@ -28,6 +28,18 @@ def memoize(func, cache, num_args):
return result
return wrapper
class cached_property(object):
"""
Decorator that creates converts a method with a single
self argument into a property cached on the instance.
"""
def __init__(self, func):
self.func = func
def __get__(self, instance, type):
res = instance.__dict__[self.func.__name__] = self.func(instance)
return res
class Promise(object):
"""
This is just a base class for the proxy class created in
@ -288,4 +300,4 @@ def partition(predicate, values):
results = ([], [])
for item in values:
results[predicate(item)].append(item)
return results
return results