5

I'm working on a Django timesheet application and am having trouble figuring out how to include aggregate sums that equal zero. If I do something like:

entries = TimeEntry.objects.all().values("user__username").annotate(Sum("hours"))

I get all users that have time entries and their sums.

[{'username': u'bob' 'hours__sum':49}, {'username': u'jane' 'hours__sum':10}]

When I filter that by a given day:

filtered_entries = entries.filter(date="2010-05-17")

Anyone who didn't enter time for that day is excluded. Is there a way to include those users who's sums are 0?

Thanks

tomas
  • 51
  • 1

1 Answers1

0

Maybe you could try the relationship the other way round - start with users, and link to entries:

User.objects.all().values("username").annotate(Sum("timeentry__hours"))

Does that work?

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • Sorry, no dice with that either. Thanks for the suggestion though. The above gives me what I'm looking for but for all days. As soon as I put the filter in all the zero sum people are removed. I tried the filter after the annotate() and before. – tomas May 19 '10 at 17:37