I have the following simplified model:
class Part(models.Model):
identification = models.CharField(max_length=50)
parent_part = models.ForeignKey('Part',blank=True,null=True)
weight = models.DecimalField(max_digits=12,decimal_places=3)
As you can see, a Part can be composed of others parts, each with it's own weight, forming a tree. Of course, the top level part (root) will have no "parent_part".
What I'm struggling right now it to implement a way to sum all the weight of all the subparts.
All my ideas so far fall in some form of recursion that I know that should be avoided.
BAsed in my knowledge, I think that the proper solution would be through Model Managers but I'm not sure how.
Any suggestions?