mirror of
https://github.com/django/django.git
synced 2025-09-18 00:10:22 +00:00
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
This commit is contained in:
parent
2eadc418af
commit
5009e45dfe
4 changed files with 87 additions and 40 deletions
|
@ -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
|
||||
return results
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue