django static annotation
Solution 1:
Django features Value
expressions:
from django.db.models import Value
cars= Car.objects.annotate(sales=Value(0))
Prior to Django 3.2, specify the field class:
from django.db.models import Value, IntegerField
cars= Car.objects.annotate(sales=Value(0, IntegerField()))
Instead of IntegerField
you can use all available db fields classes.
Solution 2:
Update
This solution uses soon-to-be-deprecated API. See this answer for a better way to solve this.
Original Answer
You can use the extra()
method. Like this:
Car.objects.all().extra(select = {'sales': 0})