diff --git a/jobs/admin.py b/jobs/admin.py index 8c38f3f..b39ed32 100644 --- a/jobs/admin.py +++ b/jobs/admin.py @@ -1,3 +1,4 @@ from django.contrib import admin +from .models import Job -# Register your models here. +admin.site.register(Job) diff --git a/jobs/migrations/0001_initial.py b/jobs/migrations/0001_initial.py new file mode 100644 index 0000000..b9e56e2 --- /dev/null +++ b/jobs/migrations/0001_initial.py @@ -0,0 +1,31 @@ +# Generated by Django 3.1.4 on 2020-12-30 19:24 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Job', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=300)), + ('company', models.CharField(max_length=300)), + ('job_type', models.CharField(choices=[('full_time', 'Full Time'), ('part_time', 'Part Time'), ('freelance', 'Freelance'), ('internship', 'Internship'), ('temporary', 'Temporary')], default=None, max_length=20)), + ('location', models.CharField(default=None, max_length=200)), + ('description', models.TextField(default=None)), + ('publishing_date', models.DateTimeField(auto_now_add=True)), + ('slug', models.SlugField(default=None, editable=False)), + ('employer', models.ForeignKey(default=None, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/jobs/models.py b/jobs/models.py index 71a8362..5f5fa8d 100644 --- a/jobs/models.py +++ b/jobs/models.py @@ -1,3 +1,33 @@ from django.db import models +from django.template.defaultfilters import slugify -# Create your models here. +from jobportal import settings + + +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) + description = models.TextField(blank=False, default=None) + 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) + + 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',) diff --git a/jobs/views.py b/jobs/views.py index d2338c4..cb57bb8 100644 --- a/jobs/views.py +++ b/jobs/views.py @@ -1,5 +1,10 @@ -from django.views.generic import TemplateView +from django.views.generic import TemplateView, ListView + +from jobs.models import Job -class HomeView(TemplateView): - template_name = 'jobs/index.html' \ No newline at end of file +class HomeView(ListView): + template_name = 'jobs/index.html' + context_object_name = 'jobs' + model = Job + paginate_by = 1 diff --git a/templates/jobs/index.html b/templates/jobs/index.html index 92d48b6..59dae8e 100644 --- a/templates/jobs/index.html +++ b/templates/jobs/index.html @@ -223,45 +223,30 @@