Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean True/False/None

Probably stupid or already answered question here, sorry about that.

I know by definition a Boolean is supposed to have 2 values but I was wondering what is the good practice in Django to store a "third" None value let's say for optional Boolean fields.

So far I use a CharField or a ChoiceField with "yes", "no", "no_data" but I feel like it's not optimal. Is there a better way maybe using a special BooleanField that could store true/false/null or something like that?

like image 345
Cyrlop Avatar asked Jun 06 '26 08:06

Cyrlop


1 Answers

You can use NullBooleanField for this.

like image 121
neverwalkaloner Avatar answered Jun 09 '26 01:06

neverwalkaloner