from django.db import models from django.contrib.auth.models import AbstractBaseUser, BaseUserManager from django.contrib.auth.models import User class CustomUserManager(BaseUserManager): def create_user(self, phone, password=None, **extra_fields): if not phone: raise ValueError('The Phone number must be set') user = self.model(phone=phone, **extra_fields) user.set_password(password) user.save(using=self._db) return user def create_superuser(self, phone, password=None, **extra_fields): extra_fields.setdefault('is_staff', True) extra_fields.setdefault('is_superuser', True) return self.create_user(phone, password, **extra_fields) class CustomUser(AbstractBaseUser): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) phone = models.CharField(max_length=15, unique=True) phone2 = models.CharField(max_length=15, blank=True, null=True) company_email = models.EmailField(null=True) personal_email = models.EmailField(null=True) address = models.TextField(null=True) work_location = models.CharField(max_length=100, null=True) picture = models.ImageField(upload_to='profile_pics/', null=True) role = models.CharField(max_length=20) user_id = models.CharField(max_length=10, unique=True) is_active = models.BooleanField(default=True) is_staff = models.BooleanField(default=False) manager_assigned = models.CharField(max_length=100, null=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) objects = CustomUserManager() USERNAME_FIELD = 'phone' class JobPosting(models.Model): client = models.CharField(max_length=100) spoc = models.CharField(max_length=100, blank=True, null=True) start_date = models.DateField() budget_max = models.DecimalField(max_digits=10, decimal_places=2, null=True) budget_min = models.DecimalField(max_digits=10, decimal_places=2, null=True) job_description = models.TextField() special_instructions = models.CharField(max_length=200, blank=True, null=True) job_id = models.CharField(max_length=20) spoc_2 = models.CharField(max_length=100, blank=True, null=True) close_date = models.DateField() location = models.CharField(max_length=100) no_of_posting = models.IntegerField() job_type = models.CharField(max_length=20) header = models.CharField(max_length=200) experience_in_years = models.IntegerField() def __str__(self): return self.job_id class Message(models.Model): sender = models.ForeignKey(User, related_name='sent_messages', on_delete=models.CASCADE) recipient = models.ForeignKey(User, related_name='received_messages', on_delete=models.CASCADE) subject = models.CharField(max_length=255) body = models.TextField() is_read = models.BooleanField(default=False) sent_at = models.DateTimeField(auto_now_add=True) def __str__(self): return f'Message from {self.sender} to {self.recipient} - {self.subject}' class Meta: ordering = ['-sent_at']