In the end, I found a way to solve this.
The main problem was that I was trying to add information to my Person model, which was not "generated / originated" from my forms.py / models.py traditional way, but rather was "generated" on a page from my jQuery script.
I knew that I needed to create a model field and a corresponding form field that would take on a value. Initially, I thought that I should send this value to my views.py (as mentioned above). This was wrong.
When I looked at the output html pages from SessionWizardView / form_wizard, I realized that even if I called each of the form fields, for example. field = ['slider_one_value'] it was issued, for example,
<input id="id_9-slider_one_value" type="hidden" name="9-slider_one_value" value="-37"></input>
Added id_9- , as it was on the ninth page of the survey.
As a result, if I changed my jQuery to update this field at the same time as the main hidden field sent to my views, the value will be automatically saved in my model
The best part is that I can update as many fields as I want from the same script
I hope this helps someone else
My code
wizard_form.html
This calls my slider_two.js script
<script src="{% static "survey/js/slider_two.js" %}"></script>
slider_two.js
Creates a slider on the page that the user can move. Then it updates the result and the hidden field that is sent to the views
It also updates newly created hidden fields that correspond to those that were created in the model after they were processed through SessionWizardView
$('#submit').click(function() { var username = $('#hidden').val(); if (username == "") username = 0; $.post('comment.php', { hidden: username }, function(return_data) { alert(return_data); }); }); $(".slider").slider({ animate: true, range: "min", value: 0, min: -100, max: +100, step: 1, //This updates the slider-result below the slider bar so the participant can see their rating slide: function(event, ui) { $("#slider-result").html((ui.value > 0 ? '+' : '') + ui.value); //This updates the hidden form field which is read by my views.py if($(this).attr("id") == "one") $("#hidden1").val((ui.value > 0 ? '+' : '') + ui.value); //This updates the id_9-slider_one_value form field which matches the name of fields = ['slider_one_value'] after it has been rendered if($(this).attr("id") == "one") $("#id_9-slider_one_value").val(ui.value); //This updates the id_10-slider_two_value form field which matches the name of fields = ['slider_one_value'] after it has been rendered if($(this).attr("id") == "one") $("#id_10-slider_two_value").val(ui.value); .... // Update as many hidden forms fields as necessary } });
models.py
Creates database entries to store values
slider_one_value = models.SmallIntegerField(null=True, max_length=100, blank=True) slider_two_value = models.SmallIntegerField(null=True, max_length=100, blank=True)
forms.py
Creates hidden form fields to accept values โโfrom jQuery script
class SurveyFormF1(forms.ModelForm): class Meta: model = Person fields = ['slider_one_value'] widgets = {'slider_one_value' : forms.HiddenInput} class SurveyFormF2(forms.ModelForm): class Meta: model = Person fields = ['slider_two_value'] widgets = {'slider_two_value' : forms.HiddenInput}