About Nullable Boolean Fields

If you make a boolean field nullable, it will be rendered in the forms as a select field with three options: "Unknown", "Yes", and "No".

class Survey(models.Model):
    user = models.ForeignKey(
        User, on_delete=models.CASCADE
    )
    statement = models.ForeignKey(
        Statement, on_delete=models.CASCADE
    )
    has_agreed = models.BooleanField(null=True, blank=True)

Behind the scenes, it will be using forms.NullBooleanField for the form field.

Tips and Tricks Development Django 6.x Django 5.2 Django 4.2