djangosnippets.org: Latest snippets posted by insinhttps://djangosnippets.org/users/insin/2008-10-08T18:39:09.967948-05:00insinPrefill ForeignKey caches
2008-10-08T18:39:09.967948-05:00insinhttps://djangosnippets.org/snippets/1117/<p>Provides an efficient means of looking up multiple related model instances for a range of objects by pre-filling the cache attribute used by <code>SingleRelatedObjectDescriptor</code> with either complete model instances or a dict containing only specified fields, looking up all required data with a single query.</p>
<p>Example usage:</p>
<pre><code>C:\django_projects\soclone>django-admin.py shell
>>> …</code></pre>
Freely redistributableA basic darcs provider for jellyroll
2008-04-10T15:25:17.367150-05:00insinhttps://djangosnippets.org/snippets/695/<p>Basic in that it only handles the main inventory file.</p>
Freely redistributableTableSelectMultiple Widget
2007-12-19T09:49:50.732959-06:00insinhttps://djangosnippets.org/snippets/518/<p>A widget for selecting from a list of <code>Model</code> instances using <code>MultipleChoiceField</code> which renders a table row for each choice, consisting of a column for a checkbox followed by a column for each item specified in <code>item_attrs</code>, which must specify attributes of the objects passed as choices.</p>
Freely redistributableAnother means of updating a subset of a model's fields
2007-11-23T03:28:06.891551-06:00insinhttps://djangosnippets.org/snippets/481/<p>Based on the UPDATE query section of <code>Model.save()</code>, this is another means of limiting the fields which are used in an UPDATE statement and bypassing the check for object existence which is made when you use <code>Model.save()</code>.</p>
<p>Just make whatever changes you want to your model instance and …</p>
Freely redistributableImageURLField for forms
2007-09-03T18:39:34.248050-05:00insinhttps://djangosnippets.org/snippets/402/<p>A URL field specifically for images, which can validate details about the filesize, dimensions and format of an image at a given URL, without having to read the entire image into memory.</p>
<p>Requires <a href="http://www.pythonware.com/library/pil/">Python Imaging Library</a>.</p>
<p><em>4th October, 2008</em> - updated for 1.0 compatibility.</p>
Freely redistributableHidden Forms
2007-07-14T10:40:41.809290-05:00insinhttps://djangosnippets.org/snippets/316/<p>Have your forms descend from this BaseForm if you need to be able to render a valid form as hidden fields for re-submission, e.g. when showing a preview of something generated based on the form's contents.
</p>
<p>Custom form example:
</p>
<pre><code>>>> from django import newforms as forms
>>> class MyForm(HiddenBaseForm, forms.Form): …</code></pre>
Freely redistributableSort Table Headers
2007-07-11T16:25:41.589011-05:00insinhttps://djangosnippets.org/snippets/308/<p>Handles creation of <code>order_by</code> criteria based on GET parameters and provides context variables to be used when generating table header sort links which respect the current sort field and direction, reversing the direction when the same header is sorted by again.</p>
<p>Sample view:</p>
<pre><code>from somewhere import SortHeaders
from django.contrib.auth.models import …</code></pre>
Freely redistributableTemplate Query Debug
2007-03-08T18:04:39.910074-06:00insinhttps://djangosnippets.org/snippets/93/<p>I often find something like this lurking at the end of my base templates - it'll show you which queries were run while generating the current page, but they'll start out hidden so as not to be a pain.</p>
<p>Of course, before this works, you'll need to satisfy all the …</p>
Freely redistributablePaginator Tag
2007-03-02T07:06:13.184624-06:00insinhttps://djangosnippets.org/snippets/73/<p>Piggybacks on the pagination-related template context variables provided by the <code>object_list</code> generic view, adding extra context variables for use in displaying links for a given number of pages adjacent to the current page and determining if the first and last pages are included in the displayed links.</p>
<p>Also makes it …</p>
Freely redistributable