jobportal/jobs/models.py

51 lines
1.7 KiB
Python
Raw Normal View History

2020-12-21 19:53:38 +01:00
from django.db import models
2020-12-31 10:36:51 +01:00
from django.template.defaultfilters import slugify
2020-12-21 19:53:38 +01:00
2020-12-31 10:36:51 +01:00
from jobportal import settings
2021-01-13 20:24:06 +01:00
from ckeditor.fields import RichTextField
2020-12-31 10:36:51 +01:00
2020-12-31 11:11:30 +01:00
class Category(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField(default=None, editable=False)
def __str__(self):
return self.title
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Category, self).save(*args, **kwargs)
2020-12-31 15:10:53 +01:00
def job_count(self):
return self.jobs.all().count()
2020-12-31 11:11:30 +01:00
2020-12-31 10:36:51 +01:00
class Job(models.Model):
title = models.CharField(max_length=300)
company = models.CharField(max_length=300)
CHOICES = (
('full_time', 'Full Time'),
('part_time', 'Part Time'),
('freelance', 'Freelance'),
('internship', 'Internship'),
('temporary', 'Temporary'),
)
job_type = models.CharField(max_length=20, blank=False, default=None, choices=CHOICES)
location = models.CharField(max_length=200, blank=False, default=None)
2021-01-13 20:24:06 +01:00
description = RichTextField(blank=False, default=None)
2020-12-31 10:36:51 +01:00
publishing_date = models.DateTimeField(auto_now_add=True)
slug = models.SlugField(default=None, editable=False)
employer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, default=None)
2021-01-14 20:31:47 +01:00
employee = models.ManyToManyField(settings.AUTH_USER_MODEL, default=None, blank=True, related_name="job_employee")
2020-12-31 11:11:30 +01:00
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="jobs", default=None)
2020-12-31 10:36:51 +01:00
def __str__(self):
return self.title
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Job, self).save(*args, **kwargs)
class Meta:
ordering = ('-id',)