text: from django.contrib.auth.base_user import BaseUserManager
  from django.db import models
  from django.contrib.auth.models import AbstractBaseUser
  from django.contrib.auth.models import PermissionsMixin
  from django.utils import timezone
  from django.utils.translation import gettext_lazy as _
  from django.contrib.auth.validators import UnicodeUsernameValidator
  
  
  class MyUserManager(BaseUserManager):
      use_in_migrations = True
  
      def _create_user(self, username, password, **extra_fields):
          """
          Create and save a user with the given username, email, and password.
          """
          if not username:
              raise ValueError('The given username must be set')
          username = self.model.normalize_username(username)
          user = self.model(username=username, **extra_fields)
          user.set_password(password)
          user.save(using=self._db)
          return user
  
      def create_user(self, username, password=None, **extra_fields):
          extra_fields.setdefault('is_staff', False)
          extra_fields.setdefault('is_superuser', False)
          return self._create_user(username, password, **extra_fields)
  
      def create_superuser(self, username, password=None, **extra_fields):
          extra_fields.setdefault('is_staff', True)
          extra_fields.setdefault('is_superuser', True)
  
          if extra_fields.get('is_staff') is not True:
              raise ValueError('Superuser must have is_staff=True.')
          if extra_fields.get('is_superuser') is not True:
              raise ValueError('Superuser must have is_superuser=True.')
  
          return self._create_user(username, password, **extra_fields)
  
  
  class User(AbstractBaseUser, PermissionsMixin):
      pgp_public = models.TextField(null=False, blank=False)
      two_factor_auth = models.BooleanField(default=False)
      pgp_private = models.TextField(null=True, blank=True)
  
      username_validator = UnicodeUsernameValidator()
  
      username = models.CharField(
          _('username'),
          max_length=150,
          unique=True,
          help_text=_(
              'Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'),
          validators=[username_validator],
          error_messages={
              'unique': ("A user with that username already exists."),
          },
      )
      is_staff = models.BooleanField(
          _('staff status'),
          default=False,
          help_text=_(
              'Designates whether the user can log into this admin site.'),
      )
      is_active = models.BooleanField(
          _('active'),
          default=True,
          help_text=_(
              'Designates whether this user should be treated as active. '
              'Unselect this instead of deleting accounts.'
          ),
      )
      date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
  
      objects = MyUserManager()
  
      USERNAME_FIELD = 'username'
      REQUIRED_FIELDS = []
  
      def __str__(self):
          return self.username
  