I want to add a static value to the results of a database query using django (so not using \'raw\' SQL)
For example, if I have an object Car with fields make, model, and
This solution uses soon-to-be-deprecated API. See this answer for a better way to solve this.
You can use the extra() method. Like this:
Car.objects.all().extra(select = {'sales': 0})
As of Django 1.8, annotate
features Value expression:
from django.db.models import Value, IntegerField
cars= Car.objects.all().annotate(sales=Value(0, IntegerField()))
Instead of IntegerField
you can use all available db fields classes.