I want to be able to use wildcards in my django queries used fo开发者_如何学Pythonr searching. However as the documentation says:
Entry.objects.filter(headline__contains='%')
Will result in SQL that looks something like this:
SELECT ... WHERE headline LIKE '%\%%';
How do I tell django to not escape % and _ in a query. Or is there another way to implement wildcard search in django (apart from writing the sql directly)?
headline__contains='%' would mean headline is anything, no? In which case why include it in the query?
You can use the extra() method to insert a custom where clause:
Entry.objects.extra(where="headline LIKE '%'")
加载中,请稍侯......
精彩评论