try:fromdjango.utils.functionalimportcached_propertyexceptImportError:# Django < 1.4classcached_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=funcdef__get__(self,instance,type):res=instance.__dict__[self.func.__name__]=self.func(instance)returnres