diff options
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/functional.py | 14 |
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 |
