1👍
✅
This is perhaps not very efficient, but I think it will work.
for index, id in enumerate(ids, start=1):
member = Member.objects.get(pk=id)
member.mem_order = index
member.save()
Using python’s enumerate function you can iterate through the index and values of the ids list, then fetch the member with the id value in that list. Then set the mem_order to the index, and finally save it. The enumerate has start=1 so the first item in the list, ‘112’ will have the index of 1, and the value of ‘112’.
Source:stackexchange.com