djangosnippets.org: Latest snippets posted by jakecrhttps://djangosnippets.org/users/jakecr/2010-03-04T21:21:20.575861-06:00jakecrDRY template rendering decorator update
2010-03-04T21:21:20.575861-06:00jakecrhttps://djangosnippets.org/snippets/1951/<p>Based fully on <a href="http://www.djangosnippets.org/snippets/1929/">snippet 1929</a></p>
<p><strong>The update is:</strong>
It checks to see the view returns an instance of HttpResponse and returns that rather than trying to render it.
This allows you to return something like <code>HttpResponseRedirect('/')</code>, or use a normal <code>render_to_response</code> to use a different template.</p>
<p><em>Also updates cleandict …</em></p>
Freely redistributableModel Hooks
2010-01-06T22:32:37.680493-06:00jakecrhttps://djangosnippets.org/snippets/1850/<p>Runs model methods on save, create, update, delete
Similar to Rails hooks</p>
<p><strong>Usage:</strong>
<em>in models.py</em></p>
<p>from myproject.hooks import connect_hooks</p>
<p>class MyModel(models.Model):</p>
<pre><code>#...
# only on first save of a newly created object
def before_create(self): print self
def after_create(self): print self
# not on first save of a newly created object …</code></pre>
Freely redistributable