Skip to content
Advertisement

Django: Make a Queryset with annotate using an object’s property

I have a queryset in my Django views.py. I’m using annotate to add a promo property to each object based on each object’s id. However this is not working:

JavaScript

I get the error: name 'id' is not defined

Advertisement

Answer

The way you try you are trying to access a variable id. Try using the Concat function:

JavaScript

Reference: Django database Functions – Concat.

Advertisement