From 6a0da8ccedfce4eca1ccebe532c32d33b6f56703 Mon Sep 17 00:00:00 2001 From: Eligiusz Kurzawa Date: Thu, 31 Dec 2020 11:11:30 +0100 Subject: [PATCH] 5# added category model --- jobportal/settings.py | 5 +++- jobs/admin.py | 3 +- jobs/migrations/0002_auto_20201231_1043.py | 31 +++++++++++++++++++++ jobs/migrations/0003_auto_20201231_1050.py | 19 +++++++++++++ jobs/migrations/0004_auto_20201231_1058.py | 20 +++++++++++++ jobs/migrations/0005_auto_20201231_1059.py | 27 ++++++++++++++++++ jobs/migrations/0006_auto_20201231_1102.py | 19 +++++++++++++ jobs/migrations/0007_remove_job_category.py | 17 +++++++++++ jobs/migrations/0008_job_category.py | 19 +++++++++++++ jobs/models.py | 13 +++++++++ 10 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 jobs/migrations/0002_auto_20201231_1043.py create mode 100644 jobs/migrations/0003_auto_20201231_1050.py create mode 100644 jobs/migrations/0004_auto_20201231_1058.py create mode 100644 jobs/migrations/0005_auto_20201231_1059.py create mode 100644 jobs/migrations/0006_auto_20201231_1102.py create mode 100644 jobs/migrations/0007_remove_job_category.py create mode 100644 jobs/migrations/0008_job_category.py diff --git a/jobportal/settings.py b/jobportal/settings.py index 9fc5b5e..37dbcd0 100644 --- a/jobportal/settings.py +++ b/jobportal/settings.py @@ -84,7 +84,10 @@ DATABASES = { 'USER': 'root', 'PASSWORD': '', 'HOST': 'localhost', - 'PORT': '3306' + 'PORT': '3306', + 'OPTIONS': { + "init_command": "SET foreign_key_checks = 0", + } } } diff --git a/jobs/admin.py b/jobs/admin.py index b39ed32..98d8a56 100644 --- a/jobs/admin.py +++ b/jobs/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin -from .models import Job +from .models import Job, Category admin.site.register(Job) +admin.site.register(Category) diff --git a/jobs/migrations/0002_auto_20201231_1043.py b/jobs/migrations/0002_auto_20201231_1043.py new file mode 100644 index 0000000..b4a9ef5 --- /dev/null +++ b/jobs/migrations/0002_auto_20201231_1043.py @@ -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'), + ), + ] diff --git a/jobs/migrations/0003_auto_20201231_1050.py b/jobs/migrations/0003_auto_20201231_1050.py new file mode 100644 index 0000000..bcb5174 --- /dev/null +++ b/jobs/migrations/0003_auto_20201231_1050.py @@ -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'), + ), + ] diff --git a/jobs/migrations/0004_auto_20201231_1058.py b/jobs/migrations/0004_auto_20201231_1058.py new file mode 100644 index 0000000..bfcd93a --- /dev/null +++ b/jobs/migrations/0004_auto_20201231_1058.py @@ -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', + ), + ] diff --git a/jobs/migrations/0005_auto_20201231_1059.py b/jobs/migrations/0005_auto_20201231_1059.py new file mode 100644 index 0000000..68b0a08 --- /dev/null +++ b/jobs/migrations/0005_auto_20201231_1059.py @@ -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'), + ), + ] diff --git a/jobs/migrations/0006_auto_20201231_1102.py b/jobs/migrations/0006_auto_20201231_1102.py new file mode 100644 index 0000000..84029c8 --- /dev/null +++ b/jobs/migrations/0006_auto_20201231_1102.py @@ -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'), + ), + ] diff --git a/jobs/migrations/0007_remove_job_category.py b/jobs/migrations/0007_remove_job_category.py new file mode 100644 index 0000000..aad3619 --- /dev/null +++ b/jobs/migrations/0007_remove_job_category.py @@ -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', + ), + ] diff --git a/jobs/migrations/0008_job_category.py b/jobs/migrations/0008_job_category.py new file mode 100644 index 0000000..2f98f11 --- /dev/null +++ b/jobs/migrations/0008_job_category.py @@ -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'), + ), + ] diff --git a/jobs/models.py b/jobs/models.py index 5f5fa8d..f179685 100644 --- a/jobs/models.py +++ b/jobs/models.py @@ -4,6 +4,18 @@ from django.template.defaultfilters import slugify 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): title = 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) slug = models.SlugField(default=None, editable=False) 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): return self.title