from django.db import models from core.models import MyUser, AnonymousUserData from django.utils import timezone from datetime import timedelta from .helpers import rename_file class JobListing(models.Model): posting_options = [ ('M', 'Minimal'), ('S', 'Standard'), ('P', 'Premium'), ] status_choices = [ ('A', 'Aktywna'), ('C', 'Zakończona'), ('W', 'Oczekująca na sprawdzenie'), ('R', 'Zarchiwizowana'), ] paid_status = [ ('P', 'Oplacona'), ('N', 'Nieoplacona'), ('D', 'Inny status') ] posting_option = models.CharField(max_length=1, choices=posting_options) company_name = models.CharField(max_length=255) name = models.CharField(max_length=255) content = models.TextField() minsalary = models.IntegerField() maxsalary = models.IntegerField() requiresalary = models.BooleanField(null=True, default=False) webpage = models.CharField(max_length=255) localization = models.CharField(max_length=255) vat_number = models.CharField(max_length=10) created_at = models.DateTimeField(default=timezone.now) status = models.CharField(max_length=1, choices=status_choices, default='W') status_paid = models.CharField(max_length=1, choices=paid_status, default='N') # category = models.CharField(max_length=255, null=True, blank=True) expiration_date = models.DateTimeField(null=True, blank=True) image = models.CharField(max_length=255, null=True, blank=True) experience_level = models.CharField(max_length=255, null=True, blank=True) employmentType = models.CharField(max_length=255, null=True, blank=True) workFromHome = models.CharField(max_length=255) updated_at = models.DateTimeField(auto_now=True) skillLevels = models.ManyToManyField('SkillLevels', blank=True) anonymous_user_data = models.ForeignKey(AnonymousUserData, null=True, blank=True, on_delete=models.SET_NULL) created_by = models.ForeignKey(MyUser, null=True, blank=True, on_delete=models.CASCADE) first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) contact_email = models.EmailField(max_length=255, null=True, blank=True) def save(self, *args, **kwargs): if not self.id: self.expiration_date = self.created_at + timedelta(days=45) super().save(*args, **kwargs) def __str__(self): return f"{self.name} at {self.company_name}" class Skill(models.Model): skill_name = models.CharField(max_length=255) def __str__(self): return f"{self.skill_name}" class SkillLevels(models.Model): proficiency_choices = [ ('N', 'Nice to have'), ('B', 'Podstawowy'), ('M', 'Średnio zaawansowany'), ('A', 'Zaawansowany'), ('E', 'Ekspert'), ] skill_id = models.ForeignKey(Skill, on_delete=models.CASCADE) skill_level = models.CharField(max_length=1, choices=proficiency_choices,) jobposting_id = models.ForeignKey(JobListing, on_delete=models.CASCADE) class CompanyLogo(models.Model): company_logo = models.ImageField(upload_to=rename_file) company_name = models.CharField(max_length=255) def __str__(self): return f"{self.company_name}"