【发布时间】:2020-08-08 11:39:38
【问题描述】:
我有以下情况
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)
【问题讨论】:
标签: django django-models django-rest-framework django-forms django-views