Imagine I have this Django model:
class Letter(models.Model):
name = models.CharField(max_length=1, unique=True)
and too this list:
vowels = ['a', 'e', 'i', 'o', 'u']
I want to make a query over Letter
annotating a boolean field, which will be True
if name
value is in vowels
list, and False
otherwise.
I made next query:
from django.db.models import Value, F, BooleanField
letters = Letter.objects.annotate(
is_vowel=Value(F('name') in vowels, output_field=BooleanField())
)
However no matter what letters I analyze, the result is ALWAYS False
What am I doing wrong in my query, and what is the correct way to achieve the desired result?
Thanks in advance.
You can use the following query. django doc conditional expressions