Intro
First small project I’ve used Django for in a real world application! Hurrah! Small IT team that covers On Call Rota, plus other departments. It was a nightmare for the team, different shifts, and general frequent management of letting people know who to call out of hours 24/7. People rarely checked our calendars, emails or ERP system to find who to call and just randomly pick, waking two people instead.
Simply the Apps’s are individual departments which have members and date ranges who ever is on call.
Goal:
What I’d like to do is to display totals of who was on call for previous months. Currently my queryset doesn’t show the correct totals and I’m making three seperate filters for each Member and then doing a count(which i believe just gets the weekly total and not daily(which might be why its missing the actual total) and I just need some help in finding what query I need to be making instead.
Model:
ActiveDate
The cover is normally 1 week at a time but sometimes could be more or less depending on holidays taken.
The time is always 7am - 7am by detaults
View:
I’m guessing I need to query the daycount instead? Whats way should I go about this?
class RotaTotalView(TemplateView):
template_name = 'total.html'
def get(self, request):
today = date.today()
first = today.replace(day=1)
firstDayOfLastMonth = today.replace(day=1, month=today.month-1)
lastDayOfLastMonth = first - timedelta(days=1)
previous_month = str(firstDayOfLastMonth) + " " + str(lastDayOfLastMonth) #str(lastDayOfLastMonth.month)
now = date.today()
adamtotaldays = DateActive.objects.all().filter(employee=1, startdate__year=firstDayOfLastMonth.year, startdate__month=firstDayOfLastMonth.month, enddate__year=lastDayOfLastMonth.year, enddate__month=lastDayOfLastMonth.month)
stevetotaldays = DateActive.objects.all().filter(employee=2, startdate__year=firstDayOfLastMonth.year, startdate__month=firstDayOfLastMonth.month, enddate__year=lastDayOfLastMonth.year, enddate__month=lastDayOfLastMonth.month)
kyletotaldays = DateActive.objects.all().filter(employee=4, startdate__year=firstDayOfLastMonth.year, startdate__month=firstDayOfLastMonth.month, enddate__year=lastDayOfLastMonth.year, enddate__month=lastDayOfLastMonth.month)
dates = DateActive.objects.filter(startdate__lte=now, enddate__gte=now)
args = {'dates': dates, 'name': DateActive.employee, 'adamtotaldays': str(adamtotaldays.count()*7), 'steffandays': str(stevetotaldays.count()*7), 'kaldays': str(kyletotaldays.count()*7), "previous_month" : previous_month}
return render(request, self.template_name, args)