django.db.models BooleanField Example Code

BooleanField is a Python class within Django that maps Python code to a relational database Boolean column through the Django object-relational-mapper (ORM).

Django's documentation explains more about BooleanField and all of the other ORM column fields.

Note that BooleanField is defined within the django.db.models.fields module but is typically referenced from django.db.models rather than including the fields module reference.

Example 1 from django-push-notifications

django-push-notifications is a Django app for storing and interacting with push notification services such as Google's Firebase Cloud Messaging and Apple Notifications. The django-push-notification project's source code is available open source under the MIT license.

django-push-notifications / push_notifications /

from __future__ import unicode_literals

from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _

from .fields import HexIntegerField

    ("FCM", "Firebase Cloud Message"),
    ("GCM", "Google Cloud Message"),

    ("CHROME", "Chrome"),
    ("FIREFOX", "Firefox"),
    ("OPERA", "Opera"),

class Device(models.Model):
    name = models.CharField(max_length=255, verbose_name=_("Name"), 
                            blank=True, null=True)
    active = models.BooleanField(
        verbose_name=_("Is active"), default=True,
        help_text=_("Inactive devices will not be sent notifications")
    user = models.ForeignKey(
        SETTINGS["USER_MODEL"], blank=True, null=True, 
    date_created = models.DateTimeField(
        verbose_name=_("Creation date"), auto_now_add=True, null=True
    application_id = models.CharField(
        max_length=64, verbose_name=_("Application ID"),
            "Opaque application identity, should be filled in for"
            " multiple key/certificate access"
        blank=True, null=True

## source file continues here without further BooleanField examples

Sign up for a monthly email with Full Stack Python tutorials. No spam ever.

Learn More Python

Introduction to Ansible video course logo.

Deploy web apps with the Ansible configuration management tool.

Full Stack Python

Full Stack Python is an open book that explains concepts in plain language and provides helpful resources for those topics.
Updates via newsletter, Twitter & Facebook.

Matt Makai 2012-2019