djangosnippets.org: Latest snippets posted by axiakhttps://djangosnippets.org/users/axiak/2008-03-08T14:32:31.506540-06:00axiakLazily lookup dynamically for templates
2008-03-08T14:32:31.506540-06:00axiakhttps://djangosnippets.org/snippets/632/<p>If you've ever wanted to dynamically lookup values in the template layer (e.g. <code>dictionary[bar]</code>), then you've probably realized/been told to do this in the python layer. The problem is then you often to build a huge 2-D list to hold all of that data.</p>
<p>These are two solutions to …</p>
Freely redistributableScoped Cache Compatible with Django Caching Helpers
2008-02-28T19:09:32.077779-06:00axiakhttps://djangosnippets.org/snippets/624/<p>Have you ever felt the need to run multiple Django projects on the same memcached server? How about other cache backends? To scope the cache keys, you simply need to prefix. However, since a lot of Django's internals rely on <code>django.core.cache.cache</code>, you cannot easily replace it everywhere.</p>
<p>This will …</p>
Freely redistributableFunction/Stored Procedure Manager
2007-06-09T16:52:57.806670-05:00axiakhttps://djangosnippets.org/snippets/272/<p>Ever want to call stored procedures from Django easily? How about PostgreSQL functions? That's that this manager attempts to help you with. To use, just stick this in some module and in a model do:</p>
<pre><code>class Article(models.Model):
objects = ProcedureManager()
</code></pre>
<p>Now you can call procedures (MySQL or PostgreSQL only) to …</p>
Freely redistributableAvoid IE Brokenness When using Vary and Attachments
2007-04-05T12:22:16.347306-05:00axiakhttps://djangosnippets.org/snippets/157/<p>Apparently Internet Explorer (6 and 7) have a bug whereby if you blindly attach a PDF or some other file, it will choke. The problem lies in the Vary header (bug described in http://support.microsoft.com/kb/824847/en-us?spid=8722&sid=global).</p>
<p>To use, just add to the beginning of your middleware classes.</p>
Freely redistributableFilter on Multiple M2M Objects Simultaneously
2007-04-05T01:56:58.104846-05:00axiakhttps://djangosnippets.org/snippets/156/<p>This snippet should allow you to do queries not before possible using Django's ORM. It allows you to "Split" up the m2m object you are filtering on.
This is best described by example:</p>
<p>Suppose you have <code>Article</code> and <code>Tag</code>, where <code>Article</code> has a m2m relation with <code>Tag</code> (<code>related_name …</code></p>
Freely redistributable