mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #22691 -- Added aliasing to cached_property.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user