74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
from django.db import models
|
|
|
|
from accounts.models import User
|
|
|
|
|
|
class StatusChoices(models.TextChoices):
|
|
APPLIED = "APPLIED", "Applied"
|
|
SCREENING = "SCREENING", "Screening"
|
|
INTERVIEW = "INTERVIEW", "Interview"
|
|
OFFER = "OFFER", "Offer"
|
|
REJECTED = "REJECTED", "Rejected"
|
|
WITHDRAWN = "WITHDRAWN", "Withdrawn"
|
|
|
|
|
|
class JobApplication(models.Model):
|
|
user = models.ForeignKey(
|
|
User,
|
|
on_delete=models.CASCADE,
|
|
related_name="job_applications",
|
|
help_text="User who owns this job application.",
|
|
)
|
|
company_name = models.CharField(max_length=255)
|
|
position_title = models.CharField(max_length=255)
|
|
status = models.CharField(
|
|
max_length=20,
|
|
choices=StatusChoices.choices,
|
|
default=StatusChoices.APPLIED,
|
|
)
|
|
notes = models.TextField(blank=True, default="")
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta:
|
|
ordering = ["-updated_at"]
|
|
constraints = [
|
|
models.UniqueConstraint(
|
|
fields=["user", "company_name", "position_title"],
|
|
name="unique_user_job_application",
|
|
)
|
|
]
|
|
|
|
def __str__(self) -> str:
|
|
return f"{self.company_name} - {self.position_title}"
|
|
|
|
|
|
class JobUpdate(models.Model):
|
|
job_application = models.ForeignKey(
|
|
JobApplication,
|
|
on_delete=models.CASCADE,
|
|
related_name="updates",
|
|
)
|
|
from_status = models.CharField(
|
|
max_length=20,
|
|
choices=StatusChoices.choices,
|
|
null=True,
|
|
blank=True,
|
|
)
|
|
to_status = models.CharField(
|
|
max_length=20,
|
|
choices=StatusChoices.choices,
|
|
)
|
|
notes = models.TextField(blank=True, default="")
|
|
created_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
# Store metrics as JSON at update time for historical accuracy
|
|
metrics = models.JSONField(default=dict, blank=True)
|
|
|
|
class Meta:
|
|
ordering = ["-created_at"]
|
|
verbose_name = "Job Update"
|
|
verbose_name_plural = "Job Updates"
|
|
|
|
def __str__(self) -> str:
|
|
return f"Update #{self.id}: {self.job_application.company_name} -> {self.to_status}" |