python - Unable to get data in form of list in django jquery -


here script

var size = [];  var formdata = new formdata();  $("input[name='size']:checked").each(function() {            size.push($(this).val());     });  formdata.append('size[]' , size)  $.ajax({             type: "post",             data: formdata,             url : "{% url 'data_entry' %}",             cache: false,             contenttype: false,             processdata: false,             success: function(data) {               if(data == 'true'){                alert('product uploaded successfully')              }              },             error: function(response, error) {         }     }); 

the sizes array looks

["l", "m", "s"] 

and here view

def post(self, request , *args , **kwargs):         sizes = request.post.getlist('size')         print sizes         size in sizes:             size.objects.create(product=instance , name='size' , value=size) 

the list getting this

[u'l,m,s'] 

the problem facing here not able iterate on sizes list ..all sizes coming 1 string...how iterate on list?

you can split string using split() method:

size = [u'l,m,s'] size = size[0].split(',') # [u'l', u'm', u's'] 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -