Snippet List
This is a nice decorator for using the cache to save the results of expensive-to-calculate but static-per-instance model properties. There is also a decorator for when the property value is another model, and the contents of the other model should not be cached across requests.
3 levels of caching implemented:
* outermost: django cache
* middle: obj._cache (for multiple properties on a single object)
* innermost: replace the attribute on this object, so we can entirely avoid running this function a second time.
After reading the comment to my [snippet #49](http://www.djangosnippets.org/snippets/49/) it occurs to me that Python properties may not be obvious to everyone, and may be underutilized in Django models.
Here is a simple example demonstrating a property to format a Person's name.
Most of the time when you want a dropdown selector based on
a ForeignKey, you'll want to use [snippet #26](http://www.djangosnippets.org/snippets/26/)
Here's an alternative approach, perhaps useful when you want to define choices once and reuse it in different views without overriding Form `__init__`.
- dynamic
- foreignkey
- dropdown
- choices
- property
3 snippets posted so far.