我真的是Django的新手,正在尝试建立一个职位发布网站。我现在遇到了困难。我想在JobsDetailedView内添加JobsAppliedCreateView,以便它们显示在同一模板上,这样当保存来自jobsapplied模板的表单时,数据就保存在数据库中。我的看法是这样
我尝试了include标签,但没有运气
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.views.generic.edit import CreateView
from django.views.generic import DetailView, ListView
from job_post.models import JobPost, JobsApplied
class JobsCreateView(PermissionRequiredMixin, CreateView):
model = JobPost
template_name = 'job_post.html'
fields = '__all__'
permission_required = 'job_post.view_jobpost'
def form_valid(self, form):
form.instance.author = self.request.user
return super().form_valid(form)
class JobsDetailView(DetailView):
model = JobPost
template_name = 'job_post-detail.html'
class JobsListView(ListView):
model = JobPost
template_name = 'job_post-list.html'
class JobAppliedCreateView(CreateView):
model = JobsApplied
template_name = 'job_post_jobapplied.html'
fields = '__all__'
def form_valid(self, form):
form.instance.customuser = self.request.user
return super().form_valid(form)