djangosnippets.org: Latest snippets posted by DrMeershttps://djangosnippets.org/users/DrMeers/2010-05-27T23:46:39.707852-05:00DrMeersLimit queryset to objects related to parent in ManyToMany fields within admin inlines
2010-05-27T23:46:39.707852-05:00DrMeershttps://djangosnippets.org/snippets/2042/<p><code>formfield_for_manytomany</code> allows you to limit the choices/queryset for a ManyToManyField, but without direct access to the parent object. This snippet stores a reference to the parent object in <code>get_formset</code> and allows limiting of <code>ManyToManyField</code>s to objects related to the same parent object. See <code>ExampleInline</code> for example usage.</p>
<p>If for …</p>
Freely redistributableFake SSL Middleware for Tests and Local Development
2010-05-05T17:19:15.980802-05:00DrMeershttps://djangosnippets.org/snippets/2009/<p>Add <code>FakeSSLMiddleware</code> to the top of your <code>MIDDLEWARE_CLASSES</code> stack when running tests or developing locally to allow https:// links to operate correctly. Can be used in conjunction with other SSL middleware to allow critical tests to be performed.</p>
Freely redistributableSSL / HTTPS Middleware for Redirection and href Rewriting
2010-04-27T18:39:18.203132-05:00DrMeershttps://djangosnippets.org/snippets/1999/<p>See docstrings for details. To use, add to <code>MIDDLEWARE_CLASSES</code> in <code>settings.py</code>, and in your <code>views.py</code>:
</p>
<ol>
<li>
<code>from path.to.this.middleware import secure</code>
</li>
<li>
Decorate SSL views with <code>@secure</code>
</li>
</ol>
Freely redistributableDKIM Email Backend
2010-04-21T21:37:41.759902-05:00DrMeershttps://djangosnippets.org/snippets/1995/<p>Overrides the <code>_send</code> method of the default SMTP <code>EmailBackend</code> class to include a <a href="http://www.dkim.org/">DKIM</a> signature based on settings:</p>
<ol>
<li><code>DKIM_SELECTOR</code> -- e.g. <code>'selector'</code> if using <code>selector._domainkey.example.com</code></li>
<li><code>DKIM_DOMAIN</code> -- e.g. <code>'example.com'</code></li>
<li><code>DKIM_PRIVATE_KEY</code> -- full private key string, including <code>"""-----BEGIN RSA PRIVATE KEY-----"""</code>, etc</li>
</ol>
<p>You'll need <a href="http://hewgill.com/pydkim/">pydkim</a>.</p>
<p>Just include this code …</p>
Freely redistributableDRY Fieldsets
2009-06-11T06:24:14.028458-05:00DrMeershttps://djangosnippets.org/snippets/1563/<p>I've devised a DRY method of declaring django fieldsets:
</p>
<p><strong> Example usage: </strong>
</p>
<ol>
<li><p>Include the attached code in <code>fieldsets.py</code>
</p>
</li>
<li><p><code>models.py</code>:
</p>
<pre><code>from django.db import models
from fieldsets import Fieldset, ModelWithFieldsets
class Person(ModelWithFieldsets): #instead of models.Model
# this field will be placed in nameless fieldset
example_field = models.IntegerField()
# this fieldset will be …</code></pre></li></ol>
Freely redistributable