Login

Tag "boolean"

Snippet List

True Unique Boolean Model Decorator

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). The interesting thing with this, is that it's possible to assign a subset of fields to be used, so that the uniqueness of the field will be guaranteed among only the subset (look at the Example section in the code to understand this behaviour). This is a better and improved way of doing http://djangosnippets.org/snippets/2676/

  • model
  • unique
  • boolean
Read More

True Unique Boolean Decorator

Useful when you want to keep only one instance of a model to be the default one. This is a decorative way of doing the same as in http://djangosnippets.org/snippets/1830/ Can this be made better as a class decorator (not having to declare explicitly the save method) ?

  • model
  • unique
  • boolean
Read More

RequiredNullBooleanField

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 _not_ required that they answer True/Yes. The BooleanField treats None and False as False; The NullBooleanField distinguishes between None and False, but it doesn't raise any validation errors. Subclassing the NullBooleanField was better than overriding the clean method on all of our NullBooleanField instances.

  • required
  • boolean
  • bool
  • boolean-field
  • null-boolean-field
Read More

Boolean Image Flag TemplateTag

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: `{% boolean_img user.is_active %}` And get the following output: `<img src="/media/icons/accept.png" alt="True" />` All you need to do is use the custom templatetag code, load it in your template and use the `boolean_img` tag. **Adjust templates, html and images where needed**

  • image
  • templatetag
  • boolean
  • flag
Read More

4 snippets posted so far.