我有一个基本数据库,我想在同一视图中提取子数据(相关):
在模型.py公司名称:
class InvoiceHeader(models.Model):
customer = models.CharField(max_length = 255)
number = models.IntegerField(unique = True)
class InvoiceLine(models.Model):
description = models.CharField(max_length = 255)
price = models.DecimalField(max_digits = 10, decimal_places = 2)
invoiceheader = models.ForeignKey(InvoiceHeader)
在视图.py公司名称:
^{pr2}$我想要得到的是list_invoices视图中的invoice total,它包括发票行.价格(总计)对于每个invoiceheader,我可以在模板中输入:
{% for invoice in invoices %}
{{ invoice.subtotal }}
{% endfor %}
我想这是因为模型.py文件,但我已经迷路了。在
所以,任何帮助都将不胜感激。在
您要使用aggregation:
相关问题 更多 >
编程相关推荐