I have the following model in Django 1.11.10:
class Test(models.Model):
...
date_start = models.DateTimeField()
...
The following works fine:
Test.objects.annotate(day_start=TruncDate(ExpressionWrapper(F('date_start') - timedelta(hours=5), output_field=models.DateField()))
If I replace TruncDate with TruncDay or TruncMonth:
Test.objects.annotate(day_start=TruncDay(ExpressionWrapper(F('date_start') -
timedelta(hours=5), output_field=models.DateField()))
I get the following error:
ProgrammingError: syntax error at or near "%"
LINE 1: ...TE_TRUNC('day', ("test_test"."date_start" - %s)) AS "d...
Is anyone able to reproduce the problem? The goal is to shift the `date_start` field in time before applying the `Trunc*` operation. Is that possible?
Thanks!
Andrea