[Django]-How to get multiple values from a template and update multiple rows in a table? Django

4👍

Do

<input type="number" value="{{item.instock}}" name="item_{{item.id}}">

Then

if request.method == 'POST':
    data = request.POST.dict()
    data.pop('csrfmiddlewaretoken', None)
    for i in data.items():
        obj = Item.objects.get(id=i[0].split("_")[1])
        if not str(obj.instock) == str(i[1]): #here check int or char datatype since 1 not equal "1"
            obj.instock = i[1]
            obj.save()

Leave a comment