2👍
✅
You can enumerate over chunks of three with:
pd = request.POST.getlist('mylist')
pdi = iter(pd)
for pid, pname, ptotal, __ in zip(pdi, pdi, pdi, pdi):
models.Sellinvoiceitems.objects.create(
productid=pid
productname=pname,
totalnumber=ptotal,
sellinvoice = invoice,
stockid = stock
)
That being said, I would advise not to process POST
parameters yourself. You can work with a FormSet
for that [Django-doc].
Source:stackexchange.com