[Fixed]-Appending objects to a list and keeping the index intact even when certain iterations are excluded


You can manually control index as follows:

index = 0
for link in context["object_list"]:
    if link.publicreply_set.exists():
        index += 1

You can omit the final else. The point is you manually increment index only when you want to.

Leave a comment