I am trying to pass stringified json parameter and serialized form into Django view like this:
JS:
var selected_items = legalEntitiesVendorAgreements_selectize.items;
var data = $form.serializeArray();
for (var i = 0; i < selected_items.length; ++i)
{
data.push({'legal_entity_own_id' : selected_items[i]});
}
View:
def my_view (request):
list_data = json.loads(request.body)
for x in list_data:
// Do smth with x['some_predefined_field']
Basically, I have two big questions here:
- How do I combine $m_form and json_str in the data parameter
- How does my Django view code change in the part of parsing the request parameter. Specifically, will
json.loads(request.body)
and the for cycle still be working, and will Django syntaxmy_form = MyForm(request.POST)
still be valid
And don't know even when to start from. I've examined this, but I've got a bad feeling that $m_form + json_str
is not the right way here. Help me please!