在 django 中,鉴于以下模型(略微简化),我正在努力弄清楚如何获得包括组总和在内的视图
class Client(models.Model):
api_key = models.CharField(unique=True, max_length=250, primary_key=True)
name = models.CharField(unique=True, max_length=250)
class Purchase(models.Model):
purchase_date = models.DateTimeField()
client = models.ForeignKey(SavedClient, to_field='api_key')
amount_to_invoice = models.FloatField(null=True)
对于给定的月份,我想看看例如
April 2010
For Each Client that purchased this month:
* CLient: Name
* Total amount of Purchases for this month
* Total cost of purchases for this month
For each Purchase made by client:
* Date
* Amount
* Etc
我一直在研究 django 注释,但无法理解如何在特定月份对特定组的字段值求和并将信息作为变量/标签发送到模板。
任何信息,将不胜感激