The project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.3 KiB

from django.db import models
from django.contrib.auth import get_user_model
from django.urls import reverse_lazy
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)
class Meta:
ordering = ['name']
def __str__(self):
class Job(models.Model):
(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, editable=False)
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)
active = models.BooleanField(default=True)
def renew(self):
self.expires = after_30_days()
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse_lazy("jobs:job_detail", args=[])
class Question(models.Model):
''' A model to hold screening questions for a job post '''
name = models.TextField('Question Title')
job = models.ForeignKey(
Job, related_name='questions', on_delete=models.CASCADE)
def __str__(self):
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)
cover_letter = models.TextField(blank=True)
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)
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)
class JobMessage(models.Model):
"""Basic user to user messaging app"""
sender = models.ForeignKey(User, on_delete=models.CASCADE, related_name="sender")
receiver = models.ForeignKey(User, on_delete=models.CASCADE, related_name="receiver")
text = models.TextField()
date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return '{}, {}'.format(self.sender, self.text[:50])