From 5009e45dfe366ebf520eecb49d72d5a11cee1623 Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Fri, 30 Sep 2011 10:41:25 +0000 Subject: 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 --- django/utils/functional.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'django/utils') 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 -- cgit v1.3