[Django]-Django createview using primary key

4👍

Since this is a CreateView, you should build on the example in the documentation and add it in form_valid:

def form_valid(self, form):
    form.instance.engineer = Engineer.objects.get(pk=self.kwargs['pk'])
    return super(AppointmentCreate, self).form_valid(form)

Leave a comment