djangosnippets.org: Latest snippets tagged with 'boolean'https://djangosnippets.org/tags/boolean/2012-05-15T06:48:31.313836-05:00True Unique Boolean Model Decorator
2012-05-15T06:48:31.313836-05:00kunitokihttps://djangosnippets.org/snippets/2747/<p>This class decorator will help you when you want to keep a unique boolean (think a 'default' field which should only be only one set to true in a group).</p>
<p>The interesting thing with this, is that it's possible to assign a subset of fields to be used, so that …</p>
Freely redistributableTrue Unique Boolean Decorator
2012-02-06T09:23:59.851626-06:00kunitokihttps://djangosnippets.org/snippets/2676/<p>Useful when you want to keep only one instance of a model to be the default one.</p>
<p>This is a decorative way of doing the same as in http://djangosnippets.org/snippets/1830/</p>
<p>Can this be made better as a class decorator (not having to declare explicitly the save method) ?</p>
Freely redistributableRequiredNullBooleanField
2009-03-24T13:14:49.820590-05:00wwu.housinghttps://djangosnippets.org/snippets/1393/<p>In our situation, we want the user to choose either yes or no. The only requirement is that they fill out the form. It is <em>not</em> required that they answer True/Yes.</p>
<p>The BooleanField treats None and False as False; The NullBooleanField distinguishes between None and False, but it doesn't raise …</p>
Freely redistributableBoolean Image Flag TemplateTag
2008-12-22T12:38:32.169941-06:00MichaelAnckaerthttps://djangosnippets.org/snippets/1257/<p>Something I end up doing all the time, making a boolean variable show up as a nice image. With this code you can do the following:</p>
<p><code>{% boolean_img user.is_active %}</code></p>
<p>And get the following output:
<code><img src="/media/icons/accept.png" alt="True" /></code></p>
<p>All you need to do is use the custom templatetag code, …</p>
Freely redistributable