Write the code in django job post, Job list page, job details page and apply job page is different page slugify url use form related to job post.
Alright, let’s break down the task:
- Job Post Model: This is the data structure for a job posting.
- Job List Page: This is the page that lists all available job postings.
- Job Details Page: This is the page that displays detailed information about a specific job posting.
- Apply Job Page: This is the page where a user can apply for a specific job.
Let’s start:
Job Post Model
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# models.py from django.db import models from django.utils.text import slugify class JobPost(models.Model): title = models.CharField(max_length=200) description = models.TextField() slug = models.SlugField(unique=True, blank=True, editable=False) def save(self, *args, **kwargs): if not self.slug: self.slug = slugify(self.title) super(JobPost, self).save(*args, **kwargs) def __str__(self): return self.title |
Job List Page
1 2 3 4 5 6 7 |
# views.py from django.shortcuts import render from .models import JobPost def job_list(request): jobs = JobPost.objects.all() return render(request, 'job_list.html', {'jobs': jobs}) |
1 2 3 4 |
<!-- templates/job_list.html --> {% for job in jobs %} <h2><a href="{% url 'job_detail' job.slug %}">{{ job.title }}</a></h2> {% endfor %} |
Job Details Page
1 2 3 4 5 6 7 |
# views.py from django.shortcuts import render, get_object_or_404 from .models import JobPost def job_detail(request, job_slug): job = get_object_or_404(JobPost, slug=job_slug) return render(request, 'job_detail.html', {'job': job}) |
1 2 3 4 |
<!-- templates/job_detail.html --> <h1>{{ job.title }}</h1> <p>{{ job.description }}</p> <a href="{% url 'apply_job' job.slug %}">Apply Now</a> |
Apply Job Page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# views.py from django.shortcuts import render, redirect, get_object_or_404 from .models import JobPost from .forms import ApplyJobForm def apply_job(request, job_slug): job = get_object_or_404(JobPost, slug=job_slug) if request.method == "POST": form = ApplyJobForm(request.POST) if form.is_valid(): application = form.save(commit=False) application.job = job application.save() return redirect('job_list') # Redirect to wherever you want after applying else: form = ApplyJobForm() return render(request, 'apply_job.html', {'form': form, 'job': job}) |
1 2 3 4 5 6 7 8 |
# forms.py from django import forms class ApplyJobForm(forms.Form): # add whatever fields you want, like: name = forms.CharField(max_length=100) email = forms.EmailField() resume = forms.FileField() |
1 2 3 4 5 6 7 |
<!-- templates/apply_job.html --> <h1>Apply for {{ job.title }}</h1> <form method="post" enctype="multipart/form-data"> {% csrf_token %} {{ form.as_p }} <button type="submit">Apply</button> </form> |
URL Configuration
1 2 3 4 5 6 7 8 9 |
# urls.py from django.urls import path from . import views urlpatterns = [ path('jobs/', views.job_list, name='job_list'), path('jobs/<slug:job_slug>/', views.job_detail, name='job_detail'), path('jobs/<slug:job_slug>/apply/', views.apply_job, name='apply_job'), ] |
This is a very basic implementation. In a real-world scenario, you’ll want to add features like validation, user authentication, sending emails after job application, etc. But this should give you a good starting point.