You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to use a CTE as default manager, but I failed to do so:
classPeriodsManager(models.Manager):
defget_queryset(self):
# get the end date of the period, oldest period first, newest lastcte=With(
QuerySet(MembershipTypePeriods)
# MembershipTypePeriods.objects
.order_by('start_date').annotate(
end_date=Window(
partition_by=[F('membership_id')],
expression=Lead('start_date'),
order_by=F('start_date').asc()
)
))
returncte.queryset().with_cte(cte)
classMembershipTypePeriods(models.Model):
objects=PeriodsManager()
start_date=models.DateField(default=date.today)
type=models.ForeignKey(MembershipType, on_delete=RESTRICT)
membership=models.ForeignKey(Membership, on_delete=CASCADE)
Something like
classPeriodsManager(CTEManager):
defget_queryset(self):
# get the end date of the period, oldest period first, newest lastreturnsuper().get_queryset().order_by('start_date').annotate(
end_date=Window(
partition_by=[F('membership_id')],
expression=Lead('start_date'),
order_by=F('start_date').asc()
)
)
does not seems to use CTEs
The text was updated successfully, but these errors were encountered:
I tried to use a CTE as default manager, but I failed to do so:
Something like
does not seems to use CTEs
The text was updated successfully, but these errors were encountered: