On Jun 3, 1:28 am, Streamweaver <[email protected]> wrote:
> I'm pretty new to Django still and I know much is still escaping me.
> In particular I'm having trouble still with how to query subsets of
> related objects.
>
> In this case I have two Models.
>
> class Project(models.Model):
> title = models.CharField(max_length=141)
> ...
>
> class Release(models.Model):
> project_fk = models.ForeignKey(Project)
> point_estimate = models.IntegerField(choices=ESTIMATE_CHOICES,
> null=True, blank=True)
> velocity_points = models.IntegerField(choices=VELOCITY_CHOICES,
> null=True, blank=True)
> ...
>
> What I was looking to do is create a way sum the total number of
> velocity points in releases related to a Project. I also wanted to
> sum the total number of point_estimate points related to a Project.
>
> From what I see a Custom Manager would seem necessary but I'm getting
> confused on related objects and aggregating items. This is for Django
> v 1.0 and would not include v1.1 aggregation features.
>
> Thanks in advance for any insight.
This is just a wild guess, but I would try defining
Project.release_set = MyRelatedObjectManager, where
MyRelatedObjectManager would inherit the usual related object manager
used by django, and would add one simple method to it, something along
the lines of
def get_total(self, field='velocity_points'):
return sum(super(MyRelatedObjectManager, self).get_query_set
().values_list(field, flat=True))
but as I said, this is just a wild guess.
V
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---