Given the following model:
class Team(models.Model):
name = models.CharField(max_length=50)
others = DictField()
And the following code:
bahia = Team()
bahia.name = "E.C. Bahia"
bahia.others = {"title": "Ninguém nos Vence em Vibração!!!"}
bahia.save()
vicetoria = Team()
vicetoria.name = "E.C. Vicetoria"
vicetoria.others = {"title": "Vice de tudo!"}
vicetoria.save()
I want to find the object that have the word vence, (case insensitive) contained in title value of the field others.
I tried something like:
teams = Team.objects.filter(others__title__icontains="vence")
that gives me the following error:
FieldError: Join on field 'others' not permitted. Did you misspell 'title' for the lookup type?
I also already tried:
teams = Team.objects.filter(others__icontains={"title":"vence"})
that returns None and I know there is at least one collection as result.
SOLUTION:
teams = Team.objects.raw_query({"others.title": {"$regex" : "vence", "$options": "i"}})
The i option makes the search insensitive.