from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from .models import UserMenu
from itertools import groupby


def index(request):
    menu_items = UserMenu.objects.all().order_by('category', 'order')
    # Group by category
    grouped_menu_items = {k: list(v) for k, v in groupby(menu_items, lambda x: x.category)}
    return render(request, 'core/index.html', {'grouped_menu_items': grouped_menu_items})