ipv6-dot-work/jobs/models.py

63 lines
1.8 KiB
Python

from django.db import models
from django.contrib.auth import get_user_model
from .date_utils import after_30_days
User = get_user_model()
class Tag(models.Model):
name = models.CharField(max_length=255, unique=True, db_index=True)
def __str__(self):
return self.name
class Job(models.Model):
CLOSED_REASON_FILLED = 'filled'
CLOSED_REASON_NOT_FOUND = 'not-found'
CLOSED_REASON_CANCELLED = 'cancelled'
CLOSED_REASON_CHOICES = (
(CLOSED_REASON_FILLED, "Job filled"),
(CLOSED_REASON_CANCELLED, "Job Cancelled"),
(CLOSED_REASON_NOT_FOUND, "Suitable candidate not found")
)
title = models.CharField(max_length=2055)
description = models.TextField()
tags = models.ManyToManyField(Tag, related_name="jobs")
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
expires = models.DateTimeField(default=after_30_days)
closed = models.BooleanField(default=False)
close_reason = models.CharField(
max_length=2055, choices=CLOSED_REASON_CHOICES, blank=True)
posted_by = models.ForeignKey(
User, related_name="jobs", on_delete=models.CASCADE)
def renew(self):
self.expires = after_30_days()
self.save()
def __str__(self):
return self.title
class Application(models.Model):
''' A model representing applications to job '''
applicant = models.ForeignKey(
User, related_name="applications", on_delete=models.CASCADE)
job = models.ForeignKey(
Job, related_name="applications", on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = ('applicant', 'job')
def __str__(self):
return "{0} - Job: {1}".format(self.applicant, self.job)