Skip to content
Advertisement

Can’t handle two modelforms in a single submit/view flow with a FK relation?

I have the below two models

JavaScript

In my template I render all fields except for start (which I don’t render at all) in the same <form></form> wrapper. Now in my view I want to create new instances for each of the modelforms but only if both are valid.

This is what I have which throws

NOT NULL constraint failed: planner_offer.applicant_id

JavaScript

How would I fix the relation issue and is this a proper way to handle the workflow in that manner at all?

Advertisement

Answer

You should set the .applicant on the .instance of the form, and use the instance of the form_applicant, not the form_applicant itself, so:

JavaScript
Advertisement