Automatically Foreign Key in Form. How??

Hello Sorry for late reply. I did as you said but it’s not working. Can you guide me. I am messing up in views I guess.

Views

# Apply Views
class ApplyView(generic.edit.CreateView):
    form_class = forms.CandidateForm
    template_name = 'pages/Apply.html'
    slug_field = 'candidateid'
    slug_url_kwarg = 'candidateid'

    def get_initial(self, *args, **kwargs):
        initial = super(ApplyView, self).get_initial(**kwargs)
        initial['designation'] = self.kwargs['designation_id']  
        return initial

    def form_valid(self, form):
        form.instance.designation_jobid = self.kwargs['jobid']
        item = form.save()
        self.candidateid = item.candidateid
        return super(ApplyView, self).form_valid(form)

    def get_success_url(self):
        return reverse('applysuccess', kwargs={'candidateid': self.candidateid})

Urls

    path('viewjobs/<slug:jobid>/apply', views.ApplyView.as_view(), name="apply"),