5.4. Models Field Logic

  • models.BooleanField - stores a boolean (True/False) value

  • Can be None too when null=True

>>> 
... from django.db import models
... from django.utils.translation import gettext_lazy as _
...
...
... class Customer(models.Model):
...     firstname = models.CharField(verbose_name=_('First Name'), max_length=100, null=False, blank=False)
...     lastname = models.CharField(verbose_name=_('Last Name'), max_length=100, null=False, blank=False, db_index=True)
...     is_active = models.BooleanField(verbose_name=_('Is Active'), null=False, blank=False, default=True)
...
...     class Meta:
...         verbose_name = _('Customer')
...         verbose_name_plural = _('Customer')
...
...    def __str__(self):
...         return f'{self.firstname} {self.lastname}'

5.4.1. Arguments

  • blank

  • choices

  • db_column

  • db_index

  • default

  • editable

  • error_message

  • help_text

  • limit_choices_to

  • max_length

  • null

  • primary_key

  • unique

  • validators

  • verbose_name