I’ve an appointment model with starts_at, repeat_duration
I want to annotate the repeating values returned from a generated series the sum duration field till the end date
so if date of appointment on 14-07-2024, end_date is 25-07-2024 and duration is 3 days
it return 14, 17, 20, 23 as an array annotation
but what I’m getting is the same object, returned multiple times and each time it has one value of the series result
for the example it’ll be returned four times one for each value and repeat_days will be this value
object_1.repeat_days = 14
object_2.repeat_days = 17
how to make it return only one object and the values as an array
tried arrayagg to wrap the GenerateSeries but I’m getting
aggregate function calls cannot contain set-returning function calls
class AppointmentQuerySet(models.QuerySet):
def annotate_repeated_days(self, end_date):
return self.annotate(
repeat_dates=ArrayAgg(
GenerateSeries(
models.F("starts_at"), models.F("repeat_duration"), end_date
)
)
)
function:
from django.db import models
class GenerateSeries(models.Func):
function = 'generate_series'
output_field = models.DateTimeField()
def __init__(self, start, step, stop, **extra):
expressions = [
start,
stop,
step
]
super().__init__(*expressions, **extra)
any ideas?