def METHOD_NAME(self, request, context):
    context["items"] = [f for f in context["items"]]
    children_lists = {}
    for item in context["items"]:
        item.level_range = range(item.level - 1)
        item.first = False
        item.last = False
        children_lists.setdefault(item.parent_id, []).append(item)
    for level_items in children_lists.values():
        level_items[0].first = True
        level_items[-1].last = True
    return context