5# added category model

This commit is contained in:
Eligiusz Kurzawa 2020-12-31 11:11:30 +01:00
parent 4326743bee
commit 6a0da8cced
10 changed files with 171 additions and 2 deletions

View File

@ -84,7 +84,10 @@ DATABASES = {
'USER': 'root', 'USER': 'root',
'PASSWORD': '', 'PASSWORD': '',
'HOST': 'localhost', 'HOST': 'localhost',
'PORT': '3306' 'PORT': '3306',
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0",
}
} }
} }

View File

@ -1,4 +1,5 @@
from django.contrib import admin from django.contrib import admin
from .models import Job from .models import Job, Category
admin.site.register(Job) admin.site.register(Job)
admin.site.register(Category)

View File

@ -0,0 +1,31 @@
# Generated by Django 3.1.4 on 2020-12-31 09:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('jobs', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('slug', models.SlugField(default=None, editable=False)),
],
),
migrations.AlterModelOptions(
name='job',
options={'ordering': ('-id',)},
),
migrations.AddField(
model_name='job',
name='category',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='jobs', to='jobs.category'),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 3.1.4 on 2020-12-31 09:50
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('jobs', '0002_auto_20201231_1043'),
]
operations = [
migrations.AlterField(
model_name='job',
name='category',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='jobs', to='jobs.category'),
),
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.1.4 on 2020-12-31 09:58
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('jobs', '0003_auto_20201231_1050'),
]
operations = [
migrations.RemoveField(
model_name='job',
name='category',
),
migrations.DeleteModel(
name='Category',
),
]

View File

@ -0,0 +1,27 @@
# Generated by Django 3.1.4 on 2020-12-31 09:59
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('jobs', '0004_auto_20201231_1058'),
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100)),
('slug', models.SlugField(default=None, editable=False)),
],
),
migrations.AddField(
model_name='job',
name='category',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='jobs', to='jobs.category'),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 3.1.4 on 2020-12-31 10:02
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('jobs', '0005_auto_20201231_1059'),
]
operations = [
migrations.AlterField(
model_name='job',
name='category',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='jobs', to='jobs.category'),
),
]

View File

@ -0,0 +1,17 @@
# Generated by Django 3.1.4 on 2020-12-31 10:04
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('jobs', '0006_auto_20201231_1102'),
]
operations = [
migrations.RemoveField(
model_name='job',
name='category',
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 3.1.4 on 2020-12-31 10:05
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('jobs', '0007_remove_job_category'),
]
operations = [
migrations.AddField(
model_name='job',
name='category',
field=models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, related_name='jobs', to='jobs.category'),
),
]

View File

@ -4,6 +4,18 @@ from django.template.defaultfilters import slugify
from jobportal import settings from jobportal import settings
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)
class Job(models.Model): class Job(models.Model):
title = models.CharField(max_length=300) title = models.CharField(max_length=300)
company = models.CharField(max_length=300) company = models.CharField(max_length=300)
@ -21,6 +33,7 @@ class Job(models.Model):
publishing_date = models.DateTimeField(auto_now_add=True) publishing_date = models.DateTimeField(auto_now_add=True)
slug = models.SlugField(default=None, editable=False) slug = models.SlugField(default=None, editable=False)
employer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, default=None) employer = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, default=None)
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="jobs", default=None)
def __str__(self): def __str__(self):
return self.title return self.title