有没有办法根据django表过滤器对外键对象求和?
示例:
class Invoice(models.model):
some_column_1 = models.Decimal(...)
some_column_2 = models.Decimal(...)
class Payment(models.Model):
invoice = models.ForeingKey(Invoice, related_name='invoice_payments')
price = models.Decimal(...)
date_payed = models.DateField(...)
class InvoiceTable(tables.Table):
some_column_1 = tables.Column(accessor = some_column_1)
payments = = tables.Column(accessor = invoice_payments)
class Meta:
model = Invoice
class InvoiceFilter(django_filters.FilterSet):
date_from = django_filters.DateFilter(name="invoice__payments__date_payed", lookup_type='gte')
date_to = django_filters.DateFilter(name="invoice__payments__date_payed", lookup_type='lte')
model = Invoice
我需要在InvoiceTable付款列中显示此日期范围内的付款总额。有可能吗?