I am working on an open source Django time tracking app, Djime, and I'm trying to come up with a more efficient way to produce statistics. So far, we've had some rather long-winded procedural code that would get all TimeSlices for a period, and collate them together in a huge nested list/dictionary mess.
What I'd like to do is to set up a more efficient system – an object or function that would take a QuerySet of TimeSlices and collate them by user, task, and/or day.
Our model looks like this (simplified):
class TimeSlice(models.Model):
task = models.ForeignKey(Task)
user = models.ForeignKey(User)
begin = models.DateTimeField(default=datetime.datetime.now)
duration = models.PositiveIntegerField(null=True, blank=True) # Num. of seconds
note = models.TextField(null=True, blank=True)