djangosnippets.org: Latest snippets posted by sciyoshihttps://djangosnippets.org/users/sciyoshi/2009-08-08T18:16:25.348449-05:00sciyoshiEmailListField for Django
2009-08-08T18:16:25.348449-05:00sciyoshihttps://djangosnippets.org/snippets/1677/<p>A simple Django form field which validates a list of emails.
</p>
<p><a href="http://sciyoshi.com/blog/2009/aug/08/emaillistfield-django/">See this at my blog</a>
</p>
Freely redistributablePrevent Django newcomments spam with Akismet (reloaded)
2009-07-17T02:20:04.313759-05:00sciyoshihttps://djangosnippets.org/snippets/1638/<p>This is a rewrite of <a href="http://www.djangosnippets.org/snippets/1006/">snippet #1006</a> to use the moderation features available in Django's comments framework. This is more customizable than the signals approach and works well if other moderation features are being used. If you want to make comments that are flagged as spam become hidden instead of …</p>
Freely redistributableRails-like MVC Controllers for Django
2008-11-18T17:04:29.064200-06:00sciyoshihttps://djangosnippets.org/snippets/1204/<p><a href="http://sciyoshi.com/blog/2008/nov/18/rails-mvc-controllers-django/">See the blog entry</a></p>
<p>Allows using controllers for views.</p>
<p>This allows for nice subclassing to override behavior of views. <code>Controller.urls</code> (see below) works fine for subclasses as well.</p>
<p>Similar to <a href="http://www.djangosnippets.org/snippets/1165/">snippet #1165</a> except that it won't break reverse URL resolving and regex validation in URLs.</p>
<p>In <code>views.py</code>:</p>
<pre><code>import mvc …</code></pre>
Freely redistributableUsing Akismet/TypePad AntiSpam with Django's new comments framework
2008-08-27T18:27:54.252749-05:00sciyoshihttps://djangosnippets.org/snippets/1006/<p>See the description in the blog entry at <a href="http://sciyoshi.com/blog/2008/aug/27/using-akismet-djangos-new-comments-framework/">http://sciyoshi.com/blog/2008/aug/27/using-akismet-djangos-new-comments-framework/</a>
</p>
Freely redistributableCustom Django manager that excludes subclasses
2008-08-07T19:52:54.136939-05:00sciyoshihttps://djangosnippets.org/snippets/950/<p>When you're using Django model inheritance, sometimes you want to be able to get objects of the base class that aren't instances of any of the subclasses. You might expect the obvious way of doing this, <code>SuperModel.objects.filter(submodel__isnull=True)</code>, to work, but unfortunately it doesn't. (Neither does <code>SuperModel.objects.filter(submodel__supermodel_ptr=None)</code>, or any …</p>
Freely redistributableDynamic Django settings context processor
2008-07-10T22:31:28.740699-05:00sciyoshihttps://djangosnippets.org/snippets/873/<p>Here's a nice way of easily passing only certain settings variables to the template. Because of the way Django looks up context processors, we need a little hack with sys.modules. The <a href="http://sciyoshi.com/blog/2008/jul/10/dynamic-django-settings-context-processor/">blog entry is here</a>.
</p>
Freely redistributableDjango ChoiceField with "other" choice
2008-07-08T23:56:41.107371-05:00sciyoshihttps://djangosnippets.org/snippets/863/<p>See <a href="http://sciyoshi.com/blog/2008/jul/08/django-choicefield-other-choice/">the blog entry</a> for details.</p>
Freely redistributableRender specific blocks from templates (useful for AJAX)
2008-05-22T14:48:23.080400-05:00sciyoshihttps://djangosnippets.org/snippets/769/<p>Allows getting the rendered content of a specific block tag. Useful if you want to send just a part of a template back for an AJAX request. Works for arbitrary template inheritance, even if a block is defined in the child template but not in the parent.</p>
<p>Example:</p>
<p>In <code>test1.html …</code></p>
Freely redistributableCase-insensitive lookup by default
2007-07-09T00:10:05.010560-05:00sciyoshihttps://djangosnippets.org/snippets/305/<p>I wanted lookups on tags to be case insensitive by default, so that things like</p>
<pre><code>Tag.objects.get(name='Tag')
</code></pre>
<p>would return any similar tags (ignoring case differences), i.e. <code><Tag: tag></code>.</p>
<p>This snippet makes lookup on the 'name' field case-insensitive by default, although
case-sensitive lookups can still be achieved with 'name__exact'. Methods like …</p>
Freely redistributable