1π
β
In your template you have rows like
<input type="text" class="form-control" name="dose", id="dose">
It seems that each input does not have its unique id, so when you click the button on any row you get the same result. The solution could be modifying backend part with something like this:
<input type="text" class="form-control" name="dose", id="{{ item.somedoseid }}">
π€Alecx
0π
Another solution may be with pure JS only (if it is more convenient or as an example):
<button class="btn btn-light bx bx-plus" type="button" id="qty" onclick="
addItem({
'dose':this.parentNode.parentNode.children[1].firstElementChild.value,
'quantity':this.parentNode.parentNode.children[2].firstElementChild.value,
'name':'{{item.item_name}}',
'code':this.name,
'usage':{'morning':this.parentNode.parentNode.children[3].children[0].firstElementChild.checked,
'afternoon':this.parentNode.parentNode.children[3].children[1].firstElementChild.checked,
'evening':this.parentNode.parentNode.children[3].children[2].firstElementChild.checked,
'night':this.parentNode.parentNode.children[3].children[3].firstElementChild.checked,
'sos':this.parentNode.parentNode.children[3].children[4].firstElementChild.checked} })">BtnText</button>
π€Alecx
- [Answered ]-Return newly created object after creation with ModelViewSet
- [Answered ]-What is the best way to chain and filter DB queries in django?
- [Answered ]-Django Tables2 Display Multiple Tables
- [Answered ]-Best practice for adding a custom field in Django
Source:stackexchange.com