首页 > 解决方案 > django部分搜索问题

问题描述

这个需要搜索的示例文本

状态模型

    {
        "region": "National Capital Territory of Delhi",
        "country": "in"
    },
    {
        "region": "Union Territory of Chandigarh",
        "country": "in"
    },

我在服务器上有两个模型,第一个是国家模型,用户在其中选择他们居住的国家,然后从该状态过滤并显示。

所以现在如果他们Chandigarh在使用时输入他们查询

state = loginModels.State.objects.filter(country=country_code.lower()).filter(region__icontains=state).get()

它会自动选择->Union Territory of Chandigarh

但,

现在,如果用户键入NCT of Delhi上述查询失败,我也尝试Q了博客中建议的方法,这也失败了。

state = loginModels.State.objects.filter(country=country_code.lower()).filter(Q(region__icontains=query)).get()

PS 注意在这个用户代表系统,所以后端系统调用NCT和上面的查询在几个我们不想硬编码的地方失败。

任何形式的帮助将不胜感激。

标签: djangodjango-modelsdjango-rest-frameworkdjango-views

解决方案


推荐阅读