djangosnippets.org: Latest snippets posted by jediehttp://djangosnippets.org/users/jedie/2011-10-12T04:37:39.937422-05:00jedieChange model field attribute in a DRY way
2011-10-12T04:37:39.937422-05:00jediehttp://djangosnippets.org/snippets/2569/<p>Change model field attributes from a abstract base classes model in a dry way.</p>
Freely redistributableLimit ManyToMany fields in forms
2009-08-20T07:34:38.952774-05:00jediehttp://djangosnippets.org/snippets/1692/<p>Limit ManyToMany fields in forms. Hide the field, if only one item can be selected. e.g. For limit sites choices only to accessible sites.</p>
<p>Also available via django-tools: http://code.google.com/p/django-tools/</p>
Freely redistributablesimple unique_together check with M2M field
2009-08-07T08:39:08.138928-05:00jediehttp://djangosnippets.org/snippets/1676/<p>unique_together doesn't work with ManyToMany, yet. See: http://code.djangoproject.com/ticket/702</p>
<p>Here a simple test in save() that would raise a IntegrityError.</p>
Freely redistributablemanually models unique_together check via signals
2009-07-13T07:27:11.376591-05:00jediehttp://djangosnippets.org/snippets/1628/<p>signal handler for checking unique_together manually.
</p>
<p>Also available via django-tools: http://code.google.com/p/django-tools/
</p>
Freely redistributablesuperuser only decorator
2009-06-18T04:12:36.500183-05:00jediehttp://djangosnippets.org/snippets/1575/<p>Limit a view to superuser only. raise PermissionDenied.
</p>
Freely redistributableAdd model form field meta data in a DRY way
2009-03-17T06:47:41.928674-05:00jediehttp://djangosnippets.org/snippets/1375/<p>Change field meta data or add a html attribute to a ModelForm field in a DRY way.</p>
Freely redistributablelocal django model test
2008-09-11T01:11:37.192988-05:00jediehttp://djangosnippets.org/snippets/1044/<p>Sometimes you need to test some model features without a complete django app installation. Just play only with the model object. With these small script you have a complete in memory django installation.</p>
<p>Some Links:
http://www.djangosnippets.org/snippets/1044/ (en)
http://www.jensdiemer.de/permalink/150/mein-blog/99/django-db-model-test/ (de)
http://www.python-forum.de/viewtopic.php?f=3&t=15649 (de)</p>
<p>See also:
https://github.com/readevalprint/mini-django/</p>
Freely redistributableFileField with file extension whitelist
2008-08-14T01:27:35.040992-05:00jediehttp://djangosnippets.org/snippets/977/<p>A simple FileField with a addition file extension whitelist. Raised ValidationError("Not allowed filetype!") if a filename contains a extension witch is not in the whitelist.</p>
Freely redistributablechange a widget attribute in ModelForm without define the field
2008-07-25T07:01:21.451388-05:00jediehttp://djangosnippets.org/snippets/916/<p>I will change a model form widget attribute without define the complete field. Because many "meta" information are defined in the model (e.g. the help_text) and i don't want to repeat this.</p>
<p>I found a solution: Add/change the widget attribute in the <strong>init</strong>, see example code.</p>
Freely redistributablebigger textfields in admin panel
2007-09-28T12:29:13.104099-05:00jediehttp://djangosnippets.org/snippets/427/<p>Sometimes a textarea field is to small for usage. I add some JavaScript and CSS to resize all textareas a little dynamically: The JS change the size in dependence text-lengthen.</p>
<p>You should store this snippet into a file like this:
templates_django/admin/base_site.html</p>
Freely redistributableTrigger a user password change
2007-08-31T02:00:49.933588-05:00jediehttp://djangosnippets.org/snippets/397/<p>I would like to catch the raw plaintext password if a user created or change his password. First i tried to handle this with signals.post_save at the User class, like this:
</p>
<p><code>dispatcher.connect(update, signal=signals.post_save, sender=User)</code>
</p>
<p>The problem is, in the User model exists e.g. 'last_login'. So the save method called every …</p>
Freely redistributablelocal django test
2007-05-25T05:55:09.301104-05:00jediehttp://djangosnippets.org/snippets/252/<p>Sometimes I would like to test a codesnippet without a complete django environment. Here is a small "local test script" you can use for this ;)</p>
Freely redistributable