'How do you get inputs from a dynamic list in HTML

Here in this code, I want to get the list of item names in a dynamic list containing the field i.item_name as an input by which I can put in the input called item_name.

However, I don't know how to get an individual name from i.item_name to put it into the iput name "item_name" so I can add values to a table I'm creating. What should I do?

          <table class="table">
            <!-- Items list -->
            <thead>
              <tr>
                <th scope="col">Item Name</th>
                <th scope="col">Item Price</th>
                <th scope="col">Quantity</th>
                <th scope="col">Action</th>
              </tr>
            </thead>
            <tbody>
            </div>



            <form method="POST" action="{%url 'add_qty' %}">
              {% csrf_token %}
              <tr>{% for i in list_item %}</tr>

              <td>{{i.item_name}}</td>
              <td>PHP {{i.item_price}}</td>
              <td>
                <input name = "quantity" class="text">
                <input type = "hidden" name = "item_name" class="{{i.item_price}}">
              </td>
              <td>
                <button class="btn btn-primary">Add</button></td>

                {% endfor %}
            </form>
            </tr>

            <tbody>     
            </tbody>
          </table>

The models are here:

class quantity(models.Model):
    quantityr = models.IntegerField(blank=True)
    namer = models.CharField(blank=True, max_length=45)

    def getqty(self):
         return self.quantityr

    def getnamer(self):
         return self.namer

    def _str_(self):
         return str(self.namer)

Here are the views:

def add_quantity(request):
    if(request.method == "POST"):
     qty = request.POST.get('quantity')
     namerrr = request.POST.get('item_name')
     quantity.objects.create(quantityr=qty, namer=namerrr)
     return redirect('openpos')

    else:
     return render(request, 'posapp/openpos.html')

Meanwhile here is what it looks like front-end:

enter image description here



Sources

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

Source: Stack Overflow

Solution Source