0

I'm trying to annotate a queryset with a static date in Django.

With an integer (instead of a date) it works:

from django.db.models import Value, IntegerField

cars= Car.objects.all().annotate(sales=Value(0, IntegerField()))

How can I make it works with date??

from django.db.models import Value, DateField

cars= Car.objects.all().annotate(mydate=Value('2019-01-01', DateField()))
Maquisard
  • 59
  • 1
  • 6

1 Answers1

1

You can use Cast

cars= Car.objects.annotate(sales=Cast(Value('20190101'), output_field=DateField()))
ac2001
  • 726
  • 1
  • 6
  • 19