I have a book model
class Book():
...
tags=JSONField()
I have some records:
Book(..., tags=['TECH', 'BUSINESS'])
Book(..., tags=['MARKETING'])
I want to filter out the books that have tag 'Tech' or 'Business'
query = Q (
Q(tags__contains='Tech') |
Q(tags__contains='Business')
)
I've tried to use contains, contained_by, has_key, has_any_keys but got no luck. The result is always empty.
Update
It was my mistake! I found the problem, JSONField is case sensitive.
The values saved in DB were ["TECH", "BUSINESS"]
instead of ["Tech", "Business"]
.
Now the question turns out How to search in a case-insensitive manner?