I have the a model Product which has a relation with itself using the key "parent".
This way, to get the parent of a product i just do product.parent and if i want the children of a product i do product.product_set.all().
What i want to do is to do an annotate on a queryset of parent products and sum the stock of each product with the stock of its children. Something similar to this:
qs = Product.objects.filter(is_parent=True)
qs = qs.annotate(stock_sum=Sum(Product.objects.filter(parent_id=F('id')).values_list['stock']))
Is this possible? Will it result in many queries or django know a way of handling this with a few joins?