I have a CreateView as follows:
class ResumeCreateView(CreateView):
model = Resume
def form_valid(self, request, form):
candidate = Candidate.objects.get(user=self.request.user)
self.object = form.save(commit=False)
self.object.candidate = candidate
self.object.save()
f = self.request.FILES.get('file')
data = [{
'title': self.request['title'],
'name': f.name,
}]
response = JSONResponse(data, {}, response_mimetype(self.request))
response['Content-Disposition'] = 'inline; filename=files.json'
return response
here i am trying to append the candidate
instance to the Resume
models candidate field which is a ForeignKey
to the Candidate
model.
But i always receive validation error {'candidate' : 'This field is required'}
- I am using a custom form not a model form as it uses twitter bootstrap identifiers.
what am i missing ?