Model Design: Adding Params to Relationship FIelds
Hi all,
I'm working on a hour-reporting system.
Each Project has many Users, and each User has many Projects(These are
established and working nicely).
My design issue is this:
How can I assign each User an IntegerField "Hours" on each Project
they are assigned to? This Integer Field is personal to them, but must
be able to summed by the Project "Hours" count later(This last part is
trivial to design, just wanted to include)
Here's relevant code:
class Project(models.Model):
client = models.CharField(max_length=500)
name = models.CharField(max_length=500)
campaign_start_date = models.DateField()
hours = models.IntegerField(default=0)
members = models.ManyToManyField(User)
hours = models.IntegerField(default=0)
def __unicode__(self):
return self.name
class UserProfile(models.Model):
user = models.OneToOneField(User)
#Additional Attributes Defined Below
project = models.ManyToManyField(Project)
rate = models.IntegerField(default=0)
def __unicode__(self):
return self.user.username
def project_names(self):
return ', '.join([p.name for p in self.project.all()])
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALgvumX5_9C3pon3ok4ma1s3xRJTeX7RHRcGT%2BWjFVjjTAcUfQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home