diff options
| author | Curtis <curtis@tinbrain.net> | 2014-05-24 20:29:31 +1000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-07-01 06:32:53 -0400 |
| commit | 71461b14ab0c5a3801d85738fde3aedd407d7115 (patch) | |
| tree | 7bfb432215d6f7a0293bb50b0f8d36e7c7341e4f /django/utils/functional.py | |
| parent | 34ba86706f0db33d9a0ab44e4abb78703e7262a9 (diff) | |
Fixed #22691 -- Added aliasing to cached_property.
Diffstat (limited to 'django/utils/functional.py')
| -rw-r--r-- | django/utils/functional.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py index 361b0f14fb..c512084c6e 100644 --- a/django/utils/functional.py +++ b/django/utils/functional.py @@ -45,14 +45,18 @@ class cached_property(object): """ Decorator that converts a method with a single self argument into a property cached on the instance. + + Optional ``name`` argument allows you to make cached properties of other + methods. (e.g. url = cached_property(get_absolute_url, name='url') ) """ - def __init__(self, func): + def __init__(self, func, name=None): self.func = func + self.name = name or func.__name__ def __get__(self, instance, type=None): if instance is None: return self - res = instance.__dict__[self.func.__name__] = self.func(instance) + res = instance.__dict__[self.name] = self.func(instance) return res |
