feat: create home page

This commit is contained in:
2024-12-21 13:58:35 -03:00
parent c5cd92a9c7
commit 8c41336029
6 changed files with 68 additions and 8 deletions

View File

@@ -1,5 +1,18 @@
from django.shortcuts import render
from django.db.models import Sum
from django.db.models import Count, F
from comandas.models import ProductComanda
from products.models import Product
from payments.models import Payments
# Create your views here.
def home(request):
return render(request, 'home.html')
total_pagamentos = Payments.objects.aggregate(total=Sum('value'))['total']
qdt_pagamentos = Payments.objects.aggregate(total=Count('value'))['total']
pagamentos = Payments.objects.all()
produtos_mais_vendidos = ProductComanda.objects.values('product').annotate(
quantidade=Count('product'),
nome=F('product__name') ).order_by('-quantidade')[:5]
return render(request, 'home.html', {'total_pagamentos': total_pagamentos, 'pagamentos': pagamentos, 'qdt_pagamentos': qdt_pagamentos, 'produtos_mais_vendidos': produtos_mais_vendidos})