djangosnippets.org: Latest snippets posted by whiteingehttps://djangosnippets.org/users/whiteinge/2011-03-29T15:29:40.535230-05:00whiteingeModel field choices as a namedtuple
2011-03-29T15:29:40.535230-05:00whiteingehttps://djangosnippets.org/snippets/2402/<p>This is a very flexible and concise way to <a href="http://www.b-list.org/weblog/2007/nov/02/handle-choices-right-way/">Handle choices the right way</a> in model fields.</p>
<ul>
<li>Preserves order.</li>
<li>Allows both a human-readable value for display in form <code><select></code>s as well as a code-friendly short name.</li>
<li>Mimic's Django's canonical <a href="http://docs.djangoproject.com/en/1.3/ref/models/fields/#choices">choices format</a>.</li>
<li>Doesn't restrict the value type.</li>
<li>Memory efficient. …</li></ul>
Freely redistributablein_group template filter
2008-07-02T16:45:34.894554-05:00whiteingehttps://djangosnippets.org/snippets/847/<p>Allows you to search if a user belongs to a given group.</p>
<p>Along the same lines as snippet <a href="http://www.djangosnippets.org/snippets/390/">390</a>, but uses a regular <code>if</code> tag so it is more flexible.</p>
<p>(Updated for efficiency. Running a boolean test on a QuerySet avoids a bit of unnecessary overhead.)</p>
<p>(Updated to accept …</p>
Freely redistributableUse django-admin.py instead of manage.py
2008-06-13T17:37:34.721217-05:00whiteingehttps://djangosnippets.org/snippets/805/<p>A lot of people new to Django don't realize that <code>manage.py</code> is <a href="http://www.djangoproject.com/documentation/django-admin/">just a wrapper</a> around the <code>django-admin.py</code> script installed with Django and isn't needed.</p>
<p>(You may need to symlink <code>django-admin.py</code> to someplace in your system <code>PATH</code> such as <code>/usr/local/bin</code>.)</p>
<p>The most important thing it does is to set …</p>
Freely redistributableAdd special field lookups to the Admin list_filter display
2008-02-04T01:00:48.556657-06:00whiteingehttps://djangosnippets.org/snippets/581/<p>Ever wanted to add an atypical <a href="http://www.djangoproject.com/documentation/db-api/#field-lookups">field lookup</a> to the Django Admin list_filter filters, like <code>__isnull</code> or <code>__in</code>? This jQuery snippet allows you to do just that.
</p>
<p>Since you can access those additional filters by directly typing them into in the Admin URL, the tricky part is to add …</p>
Freely redistributableAdmin list_display Ajax
2008-01-29T14:07:11.823208-06:00whiteingehttps://djangosnippets.org/snippets/568/<p>Sometimes it can be time consuming to go through a bunch of objects in Django's
Admin if you only need to update one field in each. An example of this is an
<code>order</code> field that allows you to manually set the order for a queryset.</p>
<p><strong>This snippet contains examples of …</strong></p>
Freely redistributableUnobtrusvie Foldable Admin Interface
2008-01-24T11:00:31.643939-06:00whiteingehttps://djangosnippets.org/snippets/563/<p>Inspired by <a href="http://www.djangosnippets.org/snippets/550/">snippet 550</a>, this allows you to expand or collapse apps in the main Admin screen. Requires jQuery. If jquery.cookie.js is available it will remember which apps you have expanded.</p>
<p>Recommended usage:</p>
<p>Place the JavaScript in a file called <code>admin-expand.js</code>.</p>
<p>Create <code>templates/admin/base_site.html</code> in your templates directory (which …</p>
Freely redistributableRestfulView
2007-10-06T23:09:19.041589-05:00whiteingehttps://djangosnippets.org/snippets/437/<p>In the same vein as <a href="http://www.djangosnippets.org/snippets/436/">snippet 436</a>, this allows you to differentiate view logic by HTTP method such as GET, POST, PUT, DELETE.</p>
<p>This is also very useful combined with the <a href="http://www.djangosnippets.org/snippets/174/">HttpMethodsMiddleware snippet</a>.</p>
<p>I am not the author, but I have found it to be very helpful.</p>
Freely redistributable