我有以下情况
Sottocategoria | Quantità
type_1 | 100.00
type_2 | 100.00
type_1 | 100.00
我想获得一个新的表,给我以下的观点。
Sottocategoria | Quantità
type_1 | 200.00
type_2 | 100.00
这里是我的models.py,有 "quantita "和 "sottocategoria "字段的情况。
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( max_length=30)
class Materiale(models.Model):
conto = models.CharField('Conto', max_length=30, choices=(
('MATERIA PRIMA', 'MATERIA PRIMA'),
('SUSSIDIARIA', 'SUSSIDIARIA'),
))
tipologia = models.ForeignKey(Tipologia, on_delete=models.SET_NULL, null=True)
sottocategoria = models.ForeignKey(Sottocategoria, on_delete=models.SET_NULL, null=True)
quantita=models.DecimalField('Quantità',max_digits=5)