'Django POST getlist for dynamic content

I a database I have a list of products. If they are need to be found = True they will appear in the screen :

<h2>Shopping list</h2>
<section>
{% for market in markets %}
<button class="collapsible">{{market.name}}</button>
<div class="content">
  <ul>
    {% for shopping in shoppings %}
      {% if shopping.marketplace.name == market.name %}
        <div id="conteneurs">
        <div class="product"><label for="stock" class="control-label">{{shopping.name}}</label></div>
        <div class="stock"><input type="number" name="stock" value="{{shopping.quantitytobuy}}" id="stock"></div>
        <div class="checkbox"><input type="checkbox" name="found"></div>
        </div>
      {% endif %}
    {% endfor %}
  </ul>
</div>
{% endfor %}
</section>
<div id="validation">
  <div class="validation"><input type="submit" value="Found"></div>
</div>

If I found the product I can check a box. I would like to recover the amount for the products where I check the box the quantity to can update the stock of them. I have no idea where to start :

  • should I need to define a variable for the checkbox ?
  • how do I recover the quantity with the associate product for all the line checked

in the file views.py

def shopping(request):
    marketplaces = Marketplaces.objects.order_by('name')
    products = Products.objects.all().filter(buy=True)
    template = loader.get_template('stock/shopping.html')
    context =  {'markets' : marketplaces, 'shoppings' : products,  }
    return HttpResponse(template.render(context, request=request))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source