2013-07-11 59 views
0

我有下面的代碼片段:__contains過濾器不上mysql的工作,適用於本地SQLite數據庫

profiles_list = Profile.objects.filter(
    company=request.user.company, 
) 
search_query = None 
search_key = None 
if request.method == 'POST': 
    search_key = request.POST.get('skey') 
    search_query = request.POST.get('squery', None) 
    profiles_list = profiles_list.filter(
     **{'%s__contains' % search_key:search_query} 
    ) 

在我的本地開發機器SQLite數據庫,如果我在SEARCH_QUERY類型,例如「Owal」 它給我返回一個記錄,其中search_key包含「Owal」,所以我得到例如「Kowalski」。

我在帶有MySQL的生產服務器上試過它,它不起作用。你知道爲什麼嗎?

回答

1

Django documentation

SQLite不支持大小寫敏感的LIKE語句;包含的行爲 像SQLite的icontains。有關更多信息,請參閱數據庫註釋。

建議:改爲使用%s__icontains

相關問題