У меня есть следующая структура моделей:
Conto | Sottocategoria | Price | Quantity | Total* | Date of purchase
Conto 1 | Product_a | 10 | 1 | 10 | 1/01/2020
Conto 1 | Product_a | 15 | 1 | 15 | 1/01/2020
Conto 2 | Product_b | 10 | 2 | 20 | 1/02/2020
Я хочу иметь месячную сумму для каждого "conto". Примерно так:
Conto | Gen | Feb | Mar | Apr | May | Jun | ....
Conto 1 | 25 | 0 | 0 | 0 | 0 | 0 | ....
Conto 2 | 0 | 20 | 0 | 0 | 0 | 0 | ....
Вот этот мой models.py:
class Tipologia(models.Model):
nome= models.CharField('Categoria', max_length=30)
class Sottocategoria(models.Model):
tipologia = models.ForeignKey(Tipologia, on_delete=models.CASCADE)
name = models.CharField()
class Conto(models.Model):
nome=models.CharField()
class Materiale(models.Model):
conto = models.ForeignKey(Conto, on_delete=models.CASCADE, null=True)
tipologia = models.ForeignKey(Tipologia, on_delete=models.CASCADE, null=True)
sottocategoria = models.ForeignKey(Sottocategoria, on_delete=models.CASCADE, null=True)
quantita=models.DecimalField()
prezzo=models.DecimalField()
data=models.DateField(default="GG/MM/YYYY")