views:

25

answers:

1

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

A: 

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
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