2👍
✅
I have NOT tested this, but I wonder if you can reinitialize a new form with the returned form data and the instance as the new object.
form = methodThatGetsForm(somearg)
new_form = ExampleModelForm(form.cleaned_data, instance=ExampleModel.objects.get(pk=getID(somearg)))
new_form.save()
If not, there should be a way to get the data as a dictionary of key/value pairs for the fields from the form
returned, using it’s ._meta
data. I think if you send that dictionary to the form init it will assign those values to the instance object, just like sending it request.POST
.
Source:stackexchange.com