17# created apply job button
This commit is contained in:
parent
a20006b486
commit
fcac708cc8
@ -7,3 +7,9 @@ class CreateJobForm(forms.ModelForm):
|
||||
model = Job
|
||||
fields = ['title', 'company', 'location', 'job_type', 'category', 'description']
|
||||
widgets = {'job_type': forms.RadioSelect}
|
||||
|
||||
|
||||
class ApplyJobForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Job
|
||||
fields = []
|
||||
|
26
jobs/migrations/0009_auto_20210114_1950.py
Normal file
26
jobs/migrations/0009_auto_20210114_1950.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Generated by Django 3.1.4 on 2021-01-14 18:50
|
||||
|
||||
import ckeditor.fields
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('jobs', '0008_job_category'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='job',
|
||||
name='employee',
|
||||
field=models.ManyToManyField(blank=True, default=None, related_name='job_employee', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='job',
|
||||
name='description',
|
||||
field=ckeditor.fields.RichTextField(default=None),
|
||||
),
|
||||
]
|
@ -36,6 +36,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)
|
||||
employee = models.ManyToManyField(settings.AUTH_USER_MODEL, default=None, blank=True, related_name="job_employee")
|
||||
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="jobs", default=None)
|
||||
|
||||
def __str__(self):
|
||||
|
@ -3,10 +3,10 @@ from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.urls import reverse
|
||||
from django.views.generic import TemplateView, ListView, CreateView, DetailView, UpdateView
|
||||
|
||||
from django.views.generic import TemplateView, ListView, CreateView, DetailView
|
||||
|
||||
from jobs.forms import CreateJobForm
|
||||
from jobs.forms import CreateJobForm, ApplyJobForm
|
||||
from jobs.models import Job, Category
|
||||
|
||||
|
||||
@ -37,16 +37,28 @@ class CreateJobView(SuccessMessageMixin, CreateView):
|
||||
return super(CreateJobView, self).form_valid(form)
|
||||
|
||||
|
||||
class SingleJobView(DetailView):
|
||||
class SingleJobView(SuccessMessageMixin, UpdateView):
|
||||
template_name = 'jobs/single.html'
|
||||
model = Job
|
||||
context_object_name = 'job'
|
||||
form_class = ApplyJobForm
|
||||
success_message = "You applied this job!"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(SingleJobView, self).get_context_data(**kwargs)
|
||||
context['categories'] = Category.objects.all()
|
||||
context['employee_applied'] = Job.objects.get(pk=self.kwargs['pk']).employee.all().filter(id=self.request.user.id)
|
||||
return context
|
||||
|
||||
def form_valid(self, form):
|
||||
employee = self.request.user
|
||||
form.instance.employee.add(employee)
|
||||
form.save()
|
||||
return super(SingleJobView, self).form_valid(form)
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('jobs:single_job', kwargs={'slug':self.object.slug, "pk":self.object.pk})
|
||||
|
||||
|
||||
class CategoryDetailView(ListView):
|
||||
model = Job
|
||||
|
@ -19,6 +19,22 @@
|
||||
<div class="col-md-8 ftco-animate">
|
||||
<h2 class="mb-3">{{ job.title }}</h2>
|
||||
<p>{{ job.description|safe }}</p>
|
||||
<hr>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% if user.is_employee %}
|
||||
<div class="ml-auto d-flex">
|
||||
{% if employee_applied %}
|
||||
<input type="submit" value="Apply" class="btn btn-primary py-2 mr-1" disabled title="You have already applied.">
|
||||
{% else %}
|
||||
<input type="submit" value="Apply" class="btn btn-primary py-2 mr-1">
|
||||
<a href="#" class="btn btn-danger rounded-circle btn-favorite d-flex align-items-center">
|
||||
<span class="icon-heart"></span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
</div> <!-- .col-md-8 -->
|
||||
<div class="col-md-4 sidebar ftco-animate">
|
||||
|
24
users/migrations/0003_auto_20210114_1950.py
Normal file
24
users/migrations/0003_auto_20210114_1950.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Generated by Django 3.1.4 on 2021-01-14 18:50
|
||||
|
||||
import ckeditor.fields
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0002_profile'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='profile',
|
||||
name='image',
|
||||
field=models.ImageField(default='media/users/person_1.jpg', upload_to='media/users'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='profile',
|
||||
name='resume',
|
||||
field=ckeditor.fields.RichTextField(blank=True),
|
||||
),
|
||||
]
|
Loading…
Reference in New Issue
Block a user