How to get current month values from Django Model, convert to int() and sum?

I decided to implement a display of the time spent on work. To do this, you need to add some code to views.py:


current_month = datetime.now().month
minutes = Addinfo.objects.filter(date_added__month=current_month).values_list('work_minutes', flat=True)
summa = sum([int(minute) for minute in minutes])
hours = (summa // 60)

Don’t forget add new variables to context dict.

See also  Search by employee and office in Django
Author: admin

Leave a Reply

Your email address will not be published. Required fields are marked *