Skip to content
Advertisement

Saving related model objects in single view

I am beginner and I am working on Django project – risk assessment application.

I have a trouble to achieve saving on related objects for my application risk record. I am using MultiModelForm to achieve the following.

I am successfully creating Whatif instance and connecting it with GuideWordi instance on save, however, I am not able to connect my RiskRecordi instance with GuideWordi instance, but RiskRecordi instance is saved into the db (I see it through admin). I tried lot’s of research over the web, but confused now.

My models.py:

JavaScript

My views.py

JavaScript

Here are my partial view of my guideword & riskrecord submit page template which I submit together from same page (it is not full code here).

JavaScript

My forms.py:

JavaScript

Advertisement

Answer

You should check what values get saved and then debug(print) the relevant variables.

The self.kwargs['pk'] part seems kinda odd.

I don’t use MultiModelFormView but logic seems to be the same, so you could:

JavaScript
Advertisement