text: from django.conf import settings
  from django.contrib.auth.models import (
      AbstractBaseUser,
      BaseUserManager,
      Group,
      PermissionsMixin
  )
  from django.db import models
  from django.db.models.signals import post_save
  from django.dispatch import receiver
  from django.utils import timezone
  
  def user_directory_path(instance, filename):
      return f'user_{instance.id}/profile/{filename}'
  
  class CustomUserManager(BaseUserManager):
      def create_user(self, email, username, password, **extra_fields):
          if not email:
              raise ValueError('Users must have a valid email address')
          if not username:
              username = self.models.normalize_username(email.split('@')[0])
          email = self.normalize_email(email)
          username = self.model.normalize_username(username)
          user = self.model(email=email, username=username, **extra_fields)
          user.set_password(password)
          user.save(using=self._db)
          return user
          
      def create_superuser(self, email, username, password, **extra_fields):
          user = self.create_user(email=email, username=username, password=password)
          user.is_admin = True
          user.save(using=self._db)
          return user
  
  
  class User(AbstractBaseUser, PermissionsMixin):
      email = models.EmailField(blank=False, unique=True)
      username = models.CharField(max_length=50, unique=True)
      first_name = models.CharField(max_length=50, blank=True, default='')
      last_name = models.CharField(max_length=50, blank=True, default='')
      photo = models.ImageField(upload_to=user_directory_path, blank=True, null=True)
      bio = models.TextField(default='', blank=True)
      is_active = models.BooleanField(default=True)
  
      objects = CustomUserManager()
  
      USERNAME_FIELD = 'email'
      REQUIRED_FIELDS = ['username']
  
      class Meta:
          permissions = (
              ('can_view', 'can view users'),
          )
  
  
      def get_full_name(self):
          return self.username
  
      def get_short_name(self):
          return self.username
  
      def __str__(self):
          return self.username
  
      @property
      def is_staff(self):
          return 'Superusers' in [g.name for g in self.groups.all()]
      
      @property
      def is_superuser(self):
          return 'Superusers' in [g.name for g in self.groups.all()]
  