-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Description
Hi!
I have a model like
class HalfOpen(models.Model):
class Rating(models.IntegerChoices):
VERY_BAD = -2, "Very bad"
BAD = -1, "Bad"
NEUTRAL = 0, "Neutral"
GOOD = 1, "Good"
VERY_GOOD = 2, "Very good"
start_date = models.DateField(default=date.today, null=True, blank=True)
end_date = models.DateField(null=True, blank=True)
amount = models.IntegerField(default=0, verbose_name="A Number")
rating = models.IntegerField(choices=Rating.choices)
Where end_date__isnull=True
would signify that this model is still valid/hasn't yet ended.
How would I go about doing a TimeSeriesReport
over these, i.e. amount should appear in any time series column from start_date
onwards?
I kind of would have expected the following to work:
class SampleReport(ReportView):
report_model = HalfOpen
group_by = "rating"
start_date_field_name = "start_date"
end_date_field_name = "end_date"
columns = ["rating"]
time_series_pattern = "monthly"
time_series_columns = [
ComputationField.create(Sum, "amount", "total_amount", "Total"),
]
chart_settings = [
Chart(
"Amount over Time",
Chart.AREA,
data_source=["total_amount"],
title_source=["status"],
)
]
that however gives me a
django.core.exceptions.ImproperlyConfigured: date_field or [start_date_field_name and end_date_field_name] must be set for <SampleReport object at 0x105f3a240>
(I'm thinking the field names get lost in get_report_generator
here)
Additionally, since in a normal filter I'd write
HalfOpen.objects.filter(start_date__gte=start_date, Q(end_date__lte=end_date) | Q(end_date__isnull=True))
I'm not clear how I would hook that "OR" into _apply_queryset_options
especially since these are AFAICS only for the toplevel group_by
query and the Time-Series subqueries build their own in _prepare_report_dependencies
.
Can I get around re-implementing most of ReportGenerator
somehow?
Metadata
Metadata
Assignees
Labels
No labels