Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_queryset(self):
- entries = Entry.objects.filter(user=self.request.user).values(
- 'project__name'
- ).annotate(
- total_duration=Sum('duration'),
- billable_duration=Sum(
- Case(
- When(billable=True, then='duration'),
- output_field=DurationField(),
- )
- ),
- unbillable_duration=Sum(
- Case(
- When(billable=False, then='duration'),
- output_field=DurationField(),
- )
- )
- )
- def get_context_data(self, **kwargs):
- context_data = super().get_context_data(**kwargs)
- qs = self.get_dated_queryset()
- context_data['total_duration'] = qs.aggregate(Sum('total_duration'))['total_duration__sum']
- context_data['billable_duration'] = qs.aggregate(Sum('billable_duration'))['billable_duration__sum']
- context_data['unbillable_duration'] = qs.aggregate(Sum('unbillable_duration'))['unbillable_duration__sum']
- return context_data
Add Comment
Please, Sign In to add comment