views.py 577 Bytes
Newer Older
1 2 3 4
from django.urls import reverse_lazy
from django.views.generic import (
    TemplateView, ListView, CreateView
)
5 6

from .models import Job
7 8
from .forms import JobForm

9 10 11 12 13 14 15 16

class Index(TemplateView):
    template_name = 'jobs/index.html'


class JobList(ListView):
    context_object_name = 'jobs'
    model = Job
17

18 19 20 21 22 23 24 25 26 27

class JobCreate(CreateView):
    model = Job
    form_class = JobForm
    success_url = reverse_lazy("jobs:list")

    def form_valid(self, form):
        obj = form.save(commit=False)
        obj.posted_by = self.request.user
        return super().form_valid(form)