mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[1.11.x] Made the @cached_property example more consistent.
Backport of 68f0bcb012 from master
			
			
This commit is contained in:
		| @@ -477,16 +477,16 @@ https://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004 | |||||||
|         {% for friend in person.friends %} |         {% for friend in person.friends %} | ||||||
|  |  | ||||||
|     Here, ``friends()`` will be called twice. Since the instance ``person`` in |     Here, ``friends()`` will be called twice. Since the instance ``person`` in | ||||||
|     the view and the template are the same, ``@cached_property`` can avoid |     the view and the template are the same, decorating the ``friends()`` method | ||||||
|     that:: |     with ``@cached_property`` can avoid that:: | ||||||
|  |  | ||||||
|         from django.utils.functional import cached_property |         from django.utils.functional import cached_property | ||||||
|  |  | ||||||
|  |         class Person(models.Model): | ||||||
|  |  | ||||||
|             @cached_property |             @cached_property | ||||||
|             def friends(self): |             def friends(self): | ||||||
|             # expensive computation |  | ||||||
|                 ... |                 ... | ||||||
|             return friends |  | ||||||
|  |  | ||||||
|     Note that as the method is now a property, in Python code it will need to |     Note that as the method is now a property, in Python code it will need to | ||||||
|     be invoked appropriately:: |     be invoked appropriately:: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user