Hello,

I'm using Django to keep track hours spent working on "projects".  The
data model includes classes "Project" (name, description,...),
"Timecard" (user, date) , and "TimecardHours" (timecard, project,
hours).

With these models plugged in, I get a nice admin page for changing/
reviewing projects.  This includes a form for editing all of the
fields in a project (ie: name, description,...).  However, I would
like to be able to also see (not necessarily edit) 2 other things:

1: How much time was spent by each user on that project.
2: How much time was logged in each individual Timecard including that
project.

Could someone please give me an idea of what the best/easiest way to
go about this is?  Any suggestions would be much appreciated!

To give you an idea of what I had in mind.  I started modifying my
project class to have 2 new functions to give me summations of hours
by user, and hours per timecard:

def hours_per_person(self):
   '''Returns a dictionary keyed by username of how many hours each
user has worked on this project.'''
   userHours = {}
   for u in User.objects.all():
       userHours[u.username] = 0.0
   for h in TimecardHours.objects.all():
       if (h.project.id == self.id) and (h.hours > 0.0):
           for t in Timecard.objects.all():
               if h.timecard.id == t.id:
                   userHours[t.user.username] += h.hours
   return userHours

def hours_per_timecard(self):
   '''Returns a dictionary keyed by "username [yyyy-mm-dd]" of how
many hours each user has worked on this project.'''
   tcHours = {}
   for t in Timecard.objects.all():
       tcHours[t.user.username+' ['+str(t.date.year)
+"-"+str(t.date.month)+"-"+str(t.date.day)+"]"] = 0.0
   for h in TimecardHours.objects.all():
       if (h.project.id == self.id) and (h.hours > 0.0):
           for t in Timecard.objects.all():
               if h.timecard.id == t.id:
                   userHours[t.user.username+' ['+str(t.date.year)
+"-"+str(t.date.month)+"-"+str(t.date.day)+"]"] += h.hours
   return tcHours



...might there be a good way to use these functions to render to a
template?  I'm still quite new to Django so what might seem obvious to
others is still not quite obvious to me.

thanks much!
Adam

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to