djangosnippets.org: Latest snippets posted by dcwatsonhttp://djangosnippets.org/users/dcwatson/2012-09-13T15:42:50.612941-05:00dcwatsonUnique field inline formset
2012-09-13T15:42:50.612941-05:00dcwatsonhttp://djangosnippets.org/snippets/2816/<p>This method will return an inline formset class that validates values across the given field are unique among all forms. For instance:</p>
<pre><code>ApprovedUserFormSet = inlineformset_factory(Request, ApprovedUser, formset=unique_field_formset('email'), form=ApprovedUserForm)
</code></pre>
<p>Will make sure all ApprovedUser objects created for the Request have unique "email" fields.</p>
Freely redistributableDatabase Routing by URL
2010-05-25T14:36:46.690645-05:00dcwatsonhttp://djangosnippets.org/snippets/2037/<p>An example of how to select the "default" database based on the request URL instead of the model. The basic idea is that the middleware <code>process_view</code> (or <code>process_request</code>) function sets some context from the URL into thread local storage, and <code>process_response</code> deletes it. In between, any database operation will …</p>
Freely redistributableGzipFileSystemStorage
2009-09-29T15:16:21.674273-05:00dcwatsonhttp://djangosnippets.org/snippets/1747/<p><code>GzipFileSystemStorage</code> is a <code>FileSystemStorage</code> subclass that transparently compresses files.</p>
<p><a href="http://theidioteque.net/blog/2009/9/29/gzipfilesystemstorage/">More Info</a></p>
Freely redistributableFull-Text Searchable Models
2009-02-18T22:32:18.532358-06:00dcwatsonhttp://djangosnippets.org/snippets/1328/<p>A drop-in module to allow for full-text searchable models with very little effort. Tested with PostgreSQL 8.3, but should work on earlier versions with the tsearch2 module installed.</p>
Freely redistributable