[Fixed]-How do I update an instance of a Django Model with request.POST if POST is a nested array?


You can use a ModelForm to accomplish this. First define the ModelForm:

from django import forms

class QuestionForm(forms.ModelForm):
    class Meta:
        model = Question

Then, in your view:

question = Question.objects.get(pk=id)
if request.method == 'POST':
    form = QuestionForm(request.POST, instance=question)

Leave a comment