dashboard

parent 4b26ed3c
This diff is collapsed.
import calendar
from django.contrib import messages
from django.contrib.auth.models import User
from django.db.models import Count
......@@ -8,7 +10,7 @@ from PIL import Image
# Create your views here.
from catalog.models import Purchase
from catalog.models import Purchase, Search
def Dashboard(request):
......@@ -17,11 +19,31 @@ def Dashboard(request):
Request = User.objects.filter(is_active=False).count()
in_process = Purchase.objects.filter(purchased=True).exclude(progress=100).count()
return render(request, 'dashboard.html', {"Viewname": "Dashboard","Usuarios":usuarios,"Total_compras": total,"Solicitud":Request,"Descargando": in_process})
month_lst = [
{'quantity': 0, 'date': 'January'},
{'quantity': 0, 'date': 'February'},
{'quantity': 0, 'date': 'March'},
{'quantity': 0, 'date': 'April'},
{'quantity': 0, 'date': 'May'},
{'quantity': 0, 'date': 'June'},
{'quantity': 0, 'date': 'July'},
{'quantity': 0, 'date': 'August'},
{'quantity': 0, 'date': 'September'},
{'quantity': 0, 'date': 'October'},
{'quantity': 0, 'date': 'November'},
{'quantity': 0, 'date': 'December'}]
for date in Purchase.objects.filter().extra({'month': "Extract(month from aggreg_date)"}).values_list(
'month').annotate(Count('id')):
date_name = calendar.month_name[int(date[0])]
for month in month_lst:
if month['date'] == date_name:
month['quantity'] = date[1]
Searches = Search.objects.values('area').annotate(count=Count('area')).order_by('-count')[:5]
return render(request, 'dashboard.html', {"Viewname": "Dashboard","Usuarios":usuarios,"Total_compras": total,"Solicitud":Request,"Descargando": in_process, "dates":month_lst, "search": Searches})
# ----------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment