class ReportWithFormInitial(ReportView):
report_title = _("Report With Form Initial")
report_description = _("Pre-populates the client filter with the first and last client using get_initial(). "
"Shows how to set dynamic default filter values based on live data.")
report_model = SalesTransaction
date_field = "date"
group_by = "product"
columns = [
"name",
ComputationField.create(
method=Sum,
field="value",
name="value__sum",
verbose_name="Total sold $",
is_summable=True,
),
]
def get_initial(self):
from .models import Client
initial = super().get_initial()
initial["client_id"] = [Client.objects.first().pk, Client.objects.last().pk]
return initial