Is it possible to do the following without doing raw sql or post-processing in django?
dict(Language.objects.values_list('code' LOWER(),'language'))
This can be done in Django 1.8+ by importing the Lower
database function.
from django.db.models.functions import Lower
qs = Language.objects.annotate(code_lower=Lower('code')) # annotate each item in the queryset with the code_lower
values = qs.values_list('code_lower', 'language')
dictionary = dict(values)
I've split the answer into several lines for readability, you can collapse into a one liner if you prefer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With