Model parameter database update

Hello everyone,

I want to update a field on database but,
get_sample.columnDataName = request.POST.get(‘textarea’) line below gives an error. It is obviously because of columnDataName parameter which holds a string data. How can I fix it dinamically? Thank you in advance.

views.py

def edit_column(request):
 if request.method == "POST":
        nplainArray = request.POST.getlist('nplainArray[]')
        columnDataName = request.POST.get('columnDataName')
        updateText = request.POST.get('textarea')

        for value in nplainArray:
            get_sample = Samples.objects.get(id=value)
            if get_sample != None:
                get_sample.columnDataName = request.POST.get('textarea')
        get_sample.save()
        messages.success(request, "Column data is updated successfully!")
        return HttpResponseRedirect("/")

I edit the code but it still does not work. When I change columnDataName and updateText with string below, related field at database is updated with ‘textToUpdate’ string. So, it works but that is not dynamic way. Any ideas?

setattr(get_sample, 'fieldName', 'textToUpdate')

if get_sample != None:
                setattr(get_sample, columnDataName, updateText)
                get_sample.save()

I found the problem but I dont know how to fix it. I have ‘edit column’ button. When I clicked the button, code below starts working and do POST request.

Ekran Resmi 2022-07-27 12.59.21

base.html

$('#edit_column').click(function () {
          var nplainArray = []
          var plainArray = table.rows().data().toArray();
          for (var i = 0; i < plainArray.length; i++) {
              nplainArray.push(plainArray[i].id)
          }
          // get column name
          var columnDataName = table.column('.selected').dataSrc();
          $.ajax({
            type: 'POST',
            url: '/edit_column',
            data: {'nplainArray[]': nplainArray,'columnDataName': columnDataName, csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()},
          });
        });

After I clicked the ‘edit column’ button, modal appears on the screen and that form sends another POST request to the same edit_column view function so that columnDataName and nplainArray data get lost. Any help would be great to solve it?

<form method="POST" action="/edit_column" autocomplete="off">{% csrf_token %}