HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/unlimited-leads/Unlimited-Leads-Be/Admin/models.py
from django.db import models
import uuid


class Lead(models.Model):

    # # Enum choices for lead types
    # BUSINESS = 'business'
    # CONSUMER = 'consumer'
    # LEAD_TYPE_CHOICES = [
    #     (BUSINESS, 'Business'),
    #     (CONSUMER, 'Consumer'),
    # ]

    # # Enum choices for phone type
    # LAND = 'land'
    # CELL = 'cell'
    # PHONE_TYPE_CHOICES = [
    #     (LAND, 'Landline'),
    #     (CELL, 'Cell'),
    # ]

    lead_type = models.CharField(max_length=32, blank=True, null=True, db_index=True)
    lead_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
    business_name = models.CharField(max_length=255, blank=True, null=True, db_index=True)
    first_name = models.CharField(max_length=50, blank=True, null=True, db_index=True)
    last_name = models.CharField(max_length=50, blank=True, null=True)
    street_address = models.CharField(max_length=255, blank=True, null=True)
    city = models.CharField(max_length=100, blank=True, null=True, db_index=True)
    state = models.CharField(max_length=100, blank=True, null=True, db_index=True)
    country = models.CharField(max_length=100, blank=True, null=True, db_index=True)
    zipcode = models.CharField(max_length=20, blank=True, null=True)
    phone = models.CharField(max_length=20, blank=True, null=True, db_index=True)
    phone_type = models.CharField(max_length=32, blank=True, null=True)
    email = models.EmailField(blank=True, null=True, db_index=True)
    is_email_verified = models.BooleanField(default=False)
    sic_code = models.PositiveIntegerField(blank=True, null=True, db_index=True)
    created_on = models.DateTimeField(auto_now_add=True)
    is_deleted = models.BooleanField(default=False)
    hash_value = models.CharField(max_length=64, db_index=True, unique=True)  # SHA256 produces a 64-character string
    version_num = models.PositiveIntegerField(default=0)

    def __str__(self):
        return f" {self.email} ({self.lead_type})"
    
    class Meta:
        verbose_name_plural = "Leads"


class LeadData(models.Model):

    # Enum choices for file upload status
    UPLOADING = 'uploading'
    PROCESSING = 'processing'
    UPLOAD_COMPLETED = 'upload_completed'
    LOADING_COMPLETED = 'loading_completed'
    UPLOAD_FAILED = 'upload_failed'
    LOADING_FAILED = 'loading_failed'

    STATUS_CHOICES = [
        (UPLOADING, 'Uploading'),
        (PROCESSING, 'Processing'),
        (UPLOAD_COMPLETED, 'Upload Completed'),
        (UPLOAD_FAILED, 'Upload Failed'),
        (LOADING_COMPLETED, 'Loading Completed'),
        (LOADING_FAILED, 'Loading Failed'),
    ]

    file_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
    upload_start_time = models.DateTimeField(auto_now_add=True)
    upload_end_time = models.DateTimeField(null=True)
    status = models.CharField(max_length=32, choices=STATUS_CHOICES, default=UPLOADING)
    skipped_count = models.PositiveBigIntegerField(null=True, blank=True)
    task_id = models.CharField(max_length=256, null=True, blank=True)  # To store the Celery task ID
    s3_key = models.CharField(null=True, blank=True, max_length=128)
    version_num = models.PositiveIntegerField(default=0)

    def __str__(self):
        return str(self.file_id)


class TempLead(models.Model):
    """
    Temporary model for keeping new Lead data
    """
    # # Enum choices for lead types
    # BUSINESS = 'business'
    # CONSUMER = 'consumer'
    # LEAD_TYPE_CHOICES = [
    #     (BUSINESS, 'Business'),
    #     (CONSUMER, 'Consumer'),
    # ]

    # # Enum choices for phone type
    # LAND = 'land'
    # CELL = 'cell'
    # PHONE_TYPE_CHOICES = [
    #     (LAND, 'Landline'),
    #     (CELL, 'Cell'),
    # ]

    lead_type = models.CharField(max_length=32, blank=True, null=True)
    lead_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
    business_name = models.CharField(max_length=255, blank=True, null=True, db_index=True)
    first_name = models.CharField(max_length=50, blank=True, null=True, db_index=True)
    last_name = models.CharField(max_length=50, blank=True, null=True)
    street_address = models.CharField(max_length=255, blank=True, null=True)
    city = models.CharField(max_length=100, blank=True, null=True, db_index=True)
    state = models.CharField(max_length=100, blank=True, null=True, db_index=True)
    country = models.CharField(max_length=100, blank=True, null=True, db_index=True)
    zipcode = models.CharField(max_length=20, blank=True, null=True)
    phone = models.CharField(max_length=20, blank=True, null=True, db_index=True)
    phone_type = models.CharField(max_length=32, blank=True, null=True)
    email = models.EmailField(blank=True, null=True, db_index=True)
    is_email_verified = models.BooleanField(default=False)
    sic_code = models.PositiveIntegerField(blank=True, null=True, db_index=True)
    created_on = models.DateTimeField(auto_now_add=True)
    is_deleted = models.BooleanField(default=False)
    hash_value = models.CharField(max_length=64, db_index=True)  # SHA256 produces a 64-character string
    version_num = models.PositiveIntegerField(default=0)

    def __str__(self):
        return f"Temp: {self.email} ({self.lead_type})"

    class Meta:
        verbose_name_plural = "Temp_Leads"


class TemplateFile(models.Model):

    # Enum choices for file upload status
    UPLOADING = 'uploading'
    COMPLETED = 'completed'
    FAILED = 'failed'

    STATUS_CHOICES = [
        (UPLOADING, 'Uploading'),
        (COMPLETED, 'Completed'),
        (FAILED, 'Failed'),
    ]
    TYPE_CHOICES = [
        ('lead', 'lead'),
        ('email', 'email'),
        ('phone', 'phone'),
        ('both', 'both'),
    ]


    file_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
    uploaded_on = models.DateTimeField(auto_now_add=True)
    status = models.CharField(max_length=16, choices=STATUS_CHOICES, default=UPLOADING)
    is_deleted = models.BooleanField(default=False)
    s3_key = models.CharField(null=True, blank=True, max_length=128)
    type = models.CharField(max_length=16, choices=TYPE_CHOICES,null=True,blank=True)


class Country(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(max_length=255, default="")
    code = models.CharField(max_length=2, default="")
    phone_code = models.CharField(max_length=4, default="")
    is_deleted = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self) -> str:
        return f"{self.name}: {self.code}"


class State(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(max_length=255, default="")
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    is_deleted = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self) -> str:
        return f"{self.name}: {self.country}"


class City(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(max_length=255, default="")
    state = models.ForeignKey(State, on_delete=models.CASCADE)
    is_deleted = models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self) -> str:
        return f"{self.name}: {self.state}"