django static annotation

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 instances of all available model fields (ex: CharField(), …)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)