[Django]-Alias Name in Query Set

1👍

I think giving alias in Django query is not possible. However you can refer to this answer.

3👍

You can annotate the fields as you want, with the F expression:

from django.db.models import F

cityList = City.objects.using(settings.DATABASE_CONF).filter(status=1).values(
    'city_name_en', 'city_id')
# use F expression to annotate with an alias
cityList = cityList.annotate(cityname=F('city_name_en'))
👤A K

Leave a comment