2018-10-17 07:35:54 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth import get_user_model
|
2018-10-17 11:31:10 +00:00
|
|
|
from django.urls import reverse_lazy
|
2018-10-17 07:35:54 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2018-10-17 09:39:31 +00:00
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
|
|
|
|
2018-10-17 07:35:54 +00:00
|
|
|
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)
|
2018-10-17 08:51:51 +00:00
|
|
|
expires = models.DateTimeField(default=after_30_days, editable=False)
|
2018-10-17 07:35:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-10-17 11:31:10 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy("jobs:job_detail", args=[self.id])
|
|
|
|
|
2018-10-17 07:35:54 +00:00
|
|
|
|
2018-10-17 11:18:34 +00:00
|
|
|
class Question(models.Model):
|
|
|
|
''' A model to hold screening questions for a job post '''
|
2018-10-20 05:34:49 +00:00
|
|
|
name = models.TextField('Question Title')
|
2018-10-17 11:18:34 +00:00
|
|
|
job = models.ForeignKey(
|
|
|
|
Job, related_name='questions', on_delete=models.CASCADE)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
2018-10-17 07:35:54 +00:00
|
|
|
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)
|
2018-10-20 06:59:28 +00:00
|
|
|
cover_letter = models.TextField(blank=True)
|
2018-10-17 07:35:54 +00:00
|
|
|
|
|
|
|
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)
|
2018-10-17 11:18:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Answer(models.Model):
|
|
|
|
''' a model to hold answers for screening questions by job applicants '''
|
|
|
|
|
|
|
|
question = models.ForeignKey(
|
|
|
|
Question, related_name='answers', on_delete=models.CASCADE)
|
|
|
|
application = models.ForeignKey(
|
|
|
|
Application, related_name='answers', on_delete=models.CASCADE
|
|
|
|
)
|
|
|
|
text = models.TextField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = ('question', 'application')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Answer for : {0} - {1}".format(self.question, self.application)
|