0
I have a doubt that I have from the beginning of a project that I am developing and I have not yet found an answer...
I have 2 models in my project in Django:
class Turma(models.Model):
nome = models.CharField(max_length = 50)
class Pessoa(models.Model):
turma = models.ForeignKey(Turma, on_delete = models.CASCADE)
multiplicador = models.DecimalField(max_digits = 5, decimal_places = 2)
Supposing I had a class with 20 people in it, if I wanted the sum of all the multipliers, it would be something like this:
from django.db.models import Sum
turma = Turma.objects.get(pk = 1)
soma = turma.pessoa_set.aggregate(soma = Sum('multiplicador'))['soma']
But what if I want to multiply all multipliers? There is a way to achieve this without having to appeal to a go with prefetch_related?