[Django]-Boolean True/False/None

4đź‘Ť

âś…

Django has NullBooleanField this is a subclass of a BooleanField but where both null=True and blank=True hold.

In , the documentation mentions that null=True is allowed for a BooleanField, and that the NullBooleanField will probably get deprecated:

In older versions, this field doesn’t permit null=True, so you have to
use NullBooleanField instead. Using the latter is now discouraged as
it’s likely to be deprecated in a future version of Django.

In the more early versions of Django, it was thus impossible to write BooleanField(null=True), but that behavior has changed.

Regardless what will be used, the idea is that the database can store three possible values: TRUE (mapping to True), FALSE (mapping to False), and NULL (mapping to None).

Note that just like CharFields, you can set choices to let the values map on more “sensical” displays.

5đź‘Ť

You can use NullBooleanField for this.

Leave a comment