summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2011-09-30 10:41:25 +0000
committerLuke Plant <L.Plant.98@cantab.net>2011-09-30 10:41:25 +0000
commit5009e45dfe366ebf520eecb49d72d5a11cee1623 (patch)
tree0c71b07ea7f799db8eafab3274dcb521e420547a /django/utils
parent2eadc418aff64790eb5b8d06ac995c720c233e49 (diff)
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
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/functional.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py
index 1345d3b005..67b727f012 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -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 \ No newline at end of file
+ return results