鉴于以下模型:
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()
以下代码:
teams = Team.objects.filter(others__title__icontains="vence")
我想在字段其他的标题值中找到包含 vence ,(不区分大小写)字样的对象。< / p>
我尝试过类似的事情:
FieldError: Join on field 'others' not permitted. Did you misspell 'title' for the lookup type?
给了我以下错误:
teams = Team.objects.filter(others__icontains={"title":"vence"})
我也试过了:
teams = Team.objects.raw_query({"others.title": {"$regex" : "vence", "$options": "i"}})
返回None,我知道至少有一个集合。
SOLUTION:
$categories
i 选项会使搜索不敏感。
答案 0 :(得分:0)
我相信(如果我错了,请纠正我)djangotoolbox DictField不支持icontain。
要过滤Dict字段,您需要执行以下操作:
Team.objects.raw_query({'title': { $regex : /vence/i } })
查看此答案:How do I filter based on dict contents in a DictField on a model using the Django-MongoDB Engine?
此答案显示如何执行不区分大小写的mongodb查询:How do I make case-insensitive queries on Mongodb?