1. """
    
  2. The CustomPermissionsUser users email as the identifier, but uses the normal
    
  3. Django permissions model. This allows us to check that the PermissionsMixin
    
  4. includes everything that is needed to interact with the ModelBackend.
    
  5. """
    
  6. from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
    
  7. from django.db import models
    
  8. 
    
  9. from .custom_user import CustomUserManager, RemoveGroupsAndPermissions
    
  10. 
    
  11. 
    
  12. class CustomPermissionsUserManager(CustomUserManager):
    
  13.     def create_superuser(self, email, password, date_of_birth):
    
  14.         u = self.create_user(email, password=password, date_of_birth=date_of_birth)
    
  15.         u.is_superuser = True
    
  16.         u.save(using=self._db)
    
  17.         return u
    
  18. 
    
  19. 
    
  20. with RemoveGroupsAndPermissions():
    
  21. 
    
  22.     class CustomPermissionsUser(AbstractBaseUser, PermissionsMixin):
    
  23.         email = models.EmailField(
    
  24.             verbose_name="email address", max_length=255, unique=True
    
  25.         )
    
  26.         date_of_birth = models.DateField()
    
  27. 
    
  28.         custom_objects = CustomPermissionsUserManager()
    
  29. 
    
  30.         USERNAME_FIELD = "email"
    
  31.         REQUIRED_FIELDS = ["date_of_birth"]
    
  32. 
    
  33.         def __str__(self):
    
  34.             return self.email